Creating a matrix one row at a time
조회 수: 15 (최근 30일)
이전 댓글 표시
In each iteration of a loop I create a row vector
Y = [1,2,3,4,5];
then I want to add the Y's to a matrix one line at a time;
A(i) = Y;
How do I do this and why can't I find an example on line?
Thanks
댓글 수: 0
채택된 답변
TADA
2018년 12월 21일
A(i,:) = Y;
Don't Forget To Preallocates Your Matrix:
A = zeros(n, m);
Where n Would Be The Number Of Rows ( Iterations) And m Is The Length Of The Rows (5 In Your Example)
Another Approach Is To Concat The Rows At The End Of He Matrix:
A = [A;Y];
This Would Reallocate The Entire Matrix Each Iteration, so For Larger Datasets It Would Take Forever, so It's Better To Avoid This Practice.
Asfor Not Finding An Example, https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!