Function in a for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!