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일

0 개 추천

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

Tobias Dehn Nielsen
Tobias Dehn Nielsen 2021년 11월 7일
Thanks! My problem now is that the matrices are of different dimension, How do i solve that promblem? Is it possible to save the date on n different matrices?
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 ;)

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

카테고리

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

질문:

2021년 11월 1일

댓글:

2021년 12월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by