Why the error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts???
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Camilla Lincetto
el 7 de Mzo. de 2015
Comentada: Camilla Lincetto
el 7 de Mzo. de 2015
I have to create 180 matrices taking every time 60 different rows from a great Matrix called matrice_rend (239*10). So I thought I could create the follow for-loop, but matlab returns me the error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts. How can I solve my problem?
matrice_rend=[energy materials industrials consdiscr consstaples healthcare financials it tcmsvs utilities]
% the previous command creates the great Matrix from which I have to take 60 rows every time and put them into a new Matrix.
matrice=zeros(60,10,180)
for t=1:180
matrice(60,10,t)=matrice_rend([t:(60+t-1)],:)
t=t+1;
end
Can anyone help me? Thank you!
0 comentarios
Respuesta aceptada
Adam
el 7 de Mzo. de 2015
matrice(60,10,t)
is just a single element of your array that you are trying to assign to.
matrice(:,:,t) = ...
should give you what you want.
That syntax means you want to assign to all elements of the first and 2nd dimensions and singleton in the 3rd dimension - i.e. you want to assign a 60 * 10 -sized result.
2 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!