Since this is probably homework, and a loop is required, while I tend not to do homework assignments, you came pretty close. You made only two mistakes. First, you did not preallocate a, which is important for speed, but not crucial. It would still run without that line. Second, you are stuffing the elements as created into a(i,j). So you need to write it that way.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
3 Comments
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172408
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172408
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172423
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172423
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172433
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/669803-how-can-i-put-the-outputs-of-for-loop-into-a-matrix#comment_1172433
Sign in to comment.