MATLAB: Index with for loop variable name and definition

index variable nameloop variable name

I have a matrix A and avector y. I want to create a loop which names and defines them the matrix A from A1,…,A10.
for i = 1:10
A{i} = X(y==i)
end
Unfortunately this code does not work. It would be nice to end up with a double and not a cell

Best Answer

If I understand your question, it is parallel to the one here, which as Stephen Cobeldick points out is a bad idea.
There is sort of a way around this using a structure.
for i = 1:10
fname = ['A',num2str(i)];
B.(fname) = y(i);
end