for loop 2x2 matrix, do not overwrite each iteration

for i=1:5
a=[i i+1;i i-1]
end
I'm wanting to save each iteration of a so that I would end up with a 10x2 matrix in the above example.
Thanks

댓글 수: 1

Why not create a 3-d matrix? So now each matrix is just one plane of a 3-d array, of size 2x2x5? Or store each 2x2 array as one cell of a cell array of length 5?

댓글을 달려면 로그인하십시오.

 채택된 답변

Voss
Voss 2023년 1월 11일
Depends on what you want the 10x2 matrix to be, but maybe this:
a = zeros(10,2);
for i = 1:5
a(2*i-[1 0],:) = [i i+1;i i-1];
end
disp(a)
1 2 1 0 2 3 2 1 3 4 3 2 4 5 4 3 5 6 5 4

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 1월 11일

답변:

2023년 1월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by