For loop simple problem
Show older comments
i want to run this very simple for loop but the only result is a totally wrong chart and the message : " Unable to perform assignment because the indices on the left side are not compatible with the size of the right side" what does it mean ? how can solve this problem?
for i= 0.01:0.02:0.99
W1_t=i;
W2_t=1-i;
R_t=W1_t*mean(R_2(:,1))+W2_t*(R_2(:,2));
vp_t=W1_t^2*var(R_2(:,1))+W2_t^2*var(R_2(:,2))+2*W1_t*W2_t*c(2,1);
s_t=sqrt(vp_t);
figure(2)
L(1)=plot(s_t,R_t,'bx','Markersize',7);
hold on
xlim([0 5])
ylim([0 0.3])
end
Answers (1)
Walter Roberson
on 6 May 2019
0 votes
Your s_t is a scalar. Your R_t is a vector. plot is creating a vector of line handles, one for each element in R_t. That vector does not fit inside L(1)
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!