Function in a for loop

조회 수: 1 (최근 30일)
Tobias Dehn Nielsen
Tobias Dehn Nielsen 2021년 11월 1일
댓글: Tobias Dehn Nielsen 2021년 12월 2일
Hey,
I have created a function where the output i a matrix.
I want to create a for loop thats creates n different matrices based on that function. How do i do that?

답변 (1개)

Abhishek Kolla
Abhishek Kolla 2021년 11월 5일
The code snippet below should solve your question
for i=1:n
A(:,:,i)=fn();
end
where A is 3D array. More info on higher dimensional arrays can be found here Multidimensional Arrays - MATLAB & Simulink (mathworks.com)
  댓글 수: 3
Abhishek Kolla
Abhishek Kolla 2021년 11월 8일
If n is small then a simple way is to define each matrix seperately and assign the function output, otherwise the above code should work for different dimensions
Tobias Dehn Nielsen
Tobias Dehn Nielsen 2021년 12월 2일
Thanks, helped a lot ;)

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

카테고리

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