Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
I want to have a sequence of vectors using the following loop. but when i run the mat lab it will say "Subscripted assignment dimension mismatch." what can i do to index vectors and matrix.
조회 수: 1 (최근 30일)
이전 댓글 표시
for k=1:100;
x(1)=[1 4 6];
A=[1 3 -1; 2 1 5; 9 7 4];
x(k+1)=A*x(k)
end
댓글 수: 3
답변 (1개)
Dennis
2018년 8월 31일
There are a few errors in your code:
- You try to assign 3 values [1 4 6] to only one field in x. This will not work unless x is a cell or structure.
- You try to multiply a 3x3 matrix with a 1x3 matrix, i think there is no mathematical correct way to do this. I am not sure which vector is supposed to be in a 3D space.
- This is no error, but if A and x(1) never change there is no need to reassign them in every loop iteration.
I fixed the "Subscripted assignment dimension mismatch" for you. I also swapped A*x{k} to x{k}*A, but this might not be what you want to calculate.
x=cell(101,1);
A=[1 3 -1; 2 1 5; 9 7 4];
x{1}=[1 4 6];
for k=1:100
x{k+1}=x{k}*A;
end
댓글 수: 1
이 질문은 마감되었습니다.
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!