Function in a for loop
이전 댓글 표시
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
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
Tobias Dehn Nielsen
2021년 11월 7일
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
2021년 12월 2일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!