how to write values to excel sheet

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

nkumar
nkumar am 28 Jun. 2015
Bearbeitet: nkumar am 28 Jun. 2015
yes my array are same size,names are different as I specified for ex res1=[0.3 0.5 0. 9];
res2=[1.2 5.2 9.3];
val1=[20 50 13];
val2=[ 5 0 1];
like these I have 100 variables with different names,saving all variables under one name takes more time,is there any alternate solution to write into excel
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
nkumar am 28 Jun. 2015
this is what I need.In Simulink model I have used 10 'To workspace' blocks.is it possible to get all the variables and values used in 'To workspace' block
Azzi Abdelmalek
Azzi Abdelmalek am 28 Jun. 2015
Try it and you will see
nkumar
nkumar am 28 Jun. 2015
I tried it,my Simulink model consists of 'from workspace block' and other variales and values,i get error .coz of different dimensions.that the reason for posting above question,is it possible to obtain results from Simulink model using To workspace blocks
Azzi Abdelmalek
Azzi Abdelmalek am 28 Jun. 2015
Check the sizes of your data

Melden Sie sich an, um zu kommentieren.

Image Analyst
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
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
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.
nkumar
nkumar am 2 Aug. 2015
Bearbeitet: nkumar am 2 Aug. 2015
Hi sorry for late reply.I run .m first which consists of some calculations and use. Signals.values and. Time to import data into simulink using from workspace and use to workspace after some calculation .assume I have more than 20 to workspace blocks, how to write into excel my outputs.how collect all my output data into single variable so that I can use xlswrite.concatenation manually of all outputs takes time.is tere any way to process. Kindly help
Image Analyst
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.
nkumar
nkumar am 2 Aug. 2015
Bearbeitet: nkumar am 2 Aug. 2015
I have 100 array each of size 50x1 say A1,A2,A3 etc in command windows.how to write these into excel. My output variable names will differ, also I need output variable and their results.fr ex under A1 as column name I need results under it. Yes I have 100 variable with different names. How to write these data
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
nkumar am 3 Aug. 2015
I have done like this before but it is manual process Saving every variable in cell array. I like to know is any for loop will be used such tat the task become easier. Because my variable may vary Now I have A1,A2 etc.other time it may differ
Image Analyst
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.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 28 Jun. 2015

Kommentiert:

am 3 Aug. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by