필터 지우기
필터 지우기

How to assign matrices to an array in a for loop

조회 수: 1 (최근 30일)
Michael Boyte
Michael Boyte 2022년 9월 26일
답변: Rik 2022년 9월 26일
I would like to create an array that holds matrices that are calculated in a for loop.
For example, I would like to calculate matrix A and have it be assigned to matrices(1) and then calculate matrix B and have it assigned to matrices(B) and so on so that I can calculate A*B*...*n later.
I have tried:
for i = 1:5
matrices(i) = [i*1 i*2 i*3; i*4 i*5 i*6; i*7 i*8 i*9];
end
but I get this error:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Is there a way to do what I am wanting to do?

채택된 답변

Rik
Rik 2022년 9월 26일
You can use a cell array:
for i = 1:5
matrices{i} = [i*1 i*2 i*3; i*4 i*5 i*6; i*7 i*8 i*9];
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by