Вопрос

I have to make a call to read in a matrix with a name that is created from a strcat, in Matlab. For example

person = 2;
Index_XNY = strcat('Index_X',num2str(person),'Y');

Big_Index = find(Index_XNY(1,:)==1);

This works if I replace Index_XNY with Index_X2Y for this example.

I have tried a number of different things to obtain Big_Index, but so far I have not been successful. Can this be done, as there is a large collection of data elements that need to be called.

Это было полезно?

Решение

You can use the eval function to evaluate a Matlab expression in a string:

expr = strcat('find(Index_X',num2str(person),'Y(1,:)==1)');
Big_Index = eval(expr);

Of course, a lot of alternative ways to do this with eval function exist, depending on how much you would like to put into the string and how much would be left out.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top