Concatenate Three Row Vectors into an Array in a For Loop

조회 수: 1 (최근 30일)
Bob
Bob 2014년 12월 14일
편집: Image Analyst 2014년 12월 14일
What is wrong with my code?
Z=[3 8 2 4];
N=length(z);
A(i)=5*Z(i);
for i=1:N
B(i)=A(i);
C(i)=B(i)-Z(i)*3;
D(i)=C(i)-10;
E(i)=D(i)+5
end
I want to have F(i)=[B(i); C(i); D(i); E(i)] that way I can have a matrix with all the values of B(i), C(i), D(i), and E(i) obtained in the for loop.
However, I am getting this error message:
Error in sym/subsasgn (line 700)
S = builtin('subsasgn',[],S,zeros(size(B)));
Error in Program_1 (line 30)
V_total(i)=[VA(i); VB(i)]
How do I fix my code?

채택된 답변

Star Strider
Star Strider 2014년 12월 14일
Well, you didn’t actually show us the code that is throwing the error in the context of the loop it may be in, but I would change the subscripting to:
V_total(:,i)=[VA(i); VB(i)];
That adds a column to V_total for each iteration of the loop.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by