Why the error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts???

2 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Adam
Adam am 7 Mär. 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 Kommentare
Camilla Lincetto
Camilla Lincetto am 7 Mär. 2015
Thank you! Now it runs! But at the end I don't understand why my command created the conflict...
Camilla Lincetto
Camilla Lincetto am 7 Mär. 2015
Please, can you see my new problem? I have mistaken posting it as comment :-) Now I have a new problem but I don't know how solve it....! Thank you..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Camilla Lincetto
Camilla Lincetto am 7 Mär. 2015
After I solved the problem which was object of the discussion, I tried to run this loop:
t=1 while t<=180
Etrasp(t,:)=mean(matrice(:,:,t))
E(:,t)=Etrasp(t,:)'
E_msci(t)=mean(mscieurope(t:(60+t-1)))
E_bench(t)=mean(benchmark(t:(60+t-1)))
var_msci(t)=var(mscieurope(t:(60+t-1)))
var_bench(t)=var(benchmark(t:(60+t-1)))
cov_rend(:,:,t)=cov(matrice(:,:,t))
i_covrend(:,:,t)=inv(cov_rend(:,:,t))
var_rend(:,t)=diag(cov(matrice(:,:,t)))
corr_rend(:,:,t)=corrcoef(matrice(:,:,t))
uno=ones(10,1)
unotrasp=uno'
a(t)=Etrasp(t,:)*i_covrend(:,:,t)*E
b(t)=Etrasp(t,:)*i_covrend(:,:,t)*uno
c(t)=unotrasp*i_covrend(:,:,t)*uno
d(t)=((a(t)*c(t))-(b(t)^2))/c(t)
G=[0:0.05:0.5]'
delta_msci(t)=mean(mscieurope(t:(60+t-1)))-(b(t)/c(t))
delta2_msci(t)=var_msci-(1/c)
delta_bench(t)=mean(benchmark(t:(60+t-1)))-(b(t)/c(t))
delta2_bench(t)=var_bench(t)-(1/c(t))
t=t+1;
end
Now the problem is that the calculations seem to stop at the second iteration, why this??? When I do these calculation on the total sample, it is ok! And also the dimensions of vectors and matrices match. Now the problem is:In an assignment A(I) = B, the number of elements in B and I must be the same. All is ok until the second iteration and then it stop.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by