how to write values to excel sheet
Ältere Kommentare anzeigen
I have 100 variables as output say for example res1 ,res2, val1,val6 in command window.Now I want to write all these into excel sheet.In xlswrite command I am able to write as one variable xlswrite('filename.xls',res1),it takes time for writing all 100 variables,is there any easy method to do this.Another method I tried out=[res1;res2;val1;val6] and use xlswrite,for fewer variables we can cancatanate,but for 100 variables is there any easy method to do this.
Antworten (2)
Azzi Abdelmalek
am 28 Jun. 2015
0 Stimmen
Can you give more details about your arrays, are they same size? What about the names? maybe you should save all your result in one variable
6 Kommentare
Azzi Abdelmalek
am 28 Jun. 2015
You can concatenate your 100 variables
out=[res1;res2;val1]
Or do this, but the workspace should contain only your variables to concatenate
clear
a=[1 2 3];
b=[4 5 6];
c=[7 8 9];
your_var=whos
for k=1:numel(your_var)
out(k,:)=evalin('base',your_var(k).name)
end
nkumar
am 28 Jun. 2015
Azzi Abdelmalek
am 28 Jun. 2015
Try it and you will see
nkumar
am 28 Jun. 2015
Azzi Abdelmalek
am 28 Jun. 2015
Check the sizes of your data
Image Analyst
am 28 Jun. 2015
0 Stimmen
You can save all your variable to one numerical array or one cell array. Then call xlswrite(). You're not calling xlswrite 100 times are you? Because that WILL take an enormous amount of time. If you're unable to collect all your variables into one array at one time, then let me know why, and I can help you figure out how to do it. Otherwise you can use ActiveX which will be very fast even with 100 different pokes. I attach a demo for you.
8 Kommentare
Andy
am 29 Jun. 2015
I would have written the same thing, and was thinking about refining my recent work into a demo to share, but no need to know. I have a program that originally took 2 hours to run with all of the xlswrite()s, but with ""Image Analyst"'s answer there is no need to. I might just look at the demo.
Image Analyst
am 29 Jun. 2015
Just one thing to add. I'm pretty sure ActiveX only works with the Windows operating system. If you don't have that, then collecting all the various values into one single cell array and then writing that with on call to xlswrite() is the next best thing.
Image Analyst
am 2 Aug. 2015
You should be able to stuff all 100 variables into 100 cells in a few microseconds. Why do you say it "takes time"? How fast do you need it? What form does this set of 100 variables take? Do you have 100 variables all with different names? Or just a few with maybe some collected into array(s)?
I don't know Simulink so I can only help assuming that the data from Simulink has already been pulled over and is now in MATLAB variables.
Image Analyst
am 2 Aug. 2015
How do you want those in a cell? Do you want 10 cells by 10 cells? 25 cells by 4? A 100 cell column vector or row vector? Let's say you want a row vector. Then create a cell array like this:
ca{1} = A1;
ca{2} = A2;
ca{3} = A3;
.....
ca{100} = A100;
nkumar
am 3 Aug. 2015
Image Analyst
am 3 Aug. 2015
No it doesn't really get easier. That's what you get for unwisely deciding to have 100 variables with different names. Not only different but with different names on each run. What a disaster. Please read the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
You dug your own grave but it's not too late to get out. Just use regular programming methods like most people would.
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!