How to save and then append/augment a matrix into another already existing matrix?

3 views (last 30 days)
Hi guys, I have got a brief question about saving a file. I have a file named myfile.mat, (meaning this file already exists) and it contains let's say a matrix M of size 20x4 with all-zero elements. Now I want to run a code that produces a matrix N inside a loop of sizes 3x4 where 3 is the number of cycles of that loop. So putting it into a code would look like:
for j = 1:3
.
.
.
.
.
N(j,:) = [a vector of length 4];
end
In the end I will get matrix N of size Cx4. Then I would like to save N into myfile.mat by replacing the elements in M in the rows whose indices match that of the loop indices. So in the above case I would want to fill from 1st to 3rd row of M with the elements of N leaving the other elements in another rows unaffected. Should I set the cycle indices to run from let's say 5 to 10 (j=5:10) then I will fill only elements in row 5 to 10 of M.
Any suggestion for how to do this? Thanks for the help.

Accepted Answer

per isakson
per isakson on 13 Sep 2014
Edited: per isakson on 13 Sep 2014

More Answers (1)

Imam
Imam on 13 Sep 2014
Thanks to you both, that really describes the solution to my problem.

Community Treasure Hunt

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

Start Hunting!