Export iterative matlab program output in matrix to excel with a reduction in matrix size.
1 view (last 30 days)
Show older comments
I have a Matlab program that outputs 7x7 matrix for 40 times. I need to export every output from the above iteration and obtain a 6x6 matrix in excel. Is it possible?
5 Comments
dpb
on 29 Jul 2021
Edited: dpb
on 30 Jul 2021
I'd be glad to if you'd share the answers to the previous questions so know what it is you actually want for the first -- or, how you get the results to have some idea why they couldn't just as well be the wanted size instead.
We only know what you tell us, which so far is just some general statements, not details at all...
Answers (1)
dpb
on 30 Jul 2021
Edited: dpb
on 30 Jul 2021
" I would like to rid of the last row and column of the 7x7 matrix and get 6x6 for further computation. "
That would simply be if you have matrix M
M=M(1:6,1:6);
Sorry, I got interrupted and had to leave for a while...figured might as well send what had already typed..
Use writetable or writematrix instead depending upon the form -- if as above, you just have a matrix M, then writematrix is the suitable function.
Then you have to decide how you want to save the data -- then whether you want the data with/without header(s), on one or sequential sheets in the workbook, etc., etc., etc., ...
To continue to write at the end of the existing data, use the 'WriteMode', 'append'
fn=fullfile('YourRootDirectory','PickaFileNameOutput.xlsx'); % build a filename
for i=1:numberIterations
M=...calculate here...
writematrix(M(1:nToKeep,1:nToKeep),fn,"Sheet",1,"Range","WriteMode","append");
end
You can fix to use 'overwrite' (the default if don't specify at all) the first pass through the loop with an "if...else...end" construct to begin again if the file already has data in it and want to start fresh.
All up to you to decide what you want/need...
4 Comments
dpb
on 30 Jul 2021
Ybus=(Ynn-Ynr*Yrr*Yrn)
The above expression is invariant inside the loop so you'll get the same thing everytime...you have to put this somewhere in your code in which Ybus is being modified for it to have any effect.
PS: Ignore the red text; that's a fignewton of the new, fancy editor in the forum, apparently, that tried to run the code snippet when I pasted it from the above after I converted your text to code format -- and it won't let me delete it. Sometimes there's just too much "help".
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!