Creating a matrix one row at a time

6 次查看(过去 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

采纳的回答

TADA
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.

更多回答(1 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by