How to import data from MATLAB into Excel, and then have Excel save the data

Hi everyone,
I have extracted some features from images and they can be seen in the command window. There are too many blob information which needs to be saved in excel file from MATLAB command window.
Could anyone please help me how to save them in a excel file or text file automatically so that it can be used later on rather than running the process to see the values over and over unless I save them manually by copying and pasting them in text file / excel file.
Any help will be appreciated.

Answers (3)

Hi,
there exists the command
xlswrite()
Does this suit your purpose?

4 Comments

Is there any code which I can use to import data from MATLAB to excel file because if I am not wrong xlswrite() does not help me to import data from Matlab to excel and then save it.
thank you once again.
With dynamic update of data, you can use save (file) .... But I often use the database MSSQL.
fastinsert (conn, 'tablename', colnames, exdata)
These data can be easily imported into Excel.
Hi Vito,
Thank you for your suggestion but I am not sure how to do that.
If you do have any written program available as Image Analyst have given in his post, could you please give me like that.
Thanks
The images do not, but the problem is clear. Excel is not suitable. As an example, monitoring Facebook.
% insert data
exdata = []; % dataset
.....
conn = database('facebook', '', '');
colnames = {'a', 'd'}
fastinsert(conn, 'RELATION', colnames, exdata)
......................
% get data
conn = database('facebook', '', '');
curs = exec(conn,['SELECT * From RELATION']);
curs=fetch(curs);
Set=curs.Data;
Create your database and get or set data.

Sign in to comment.

See my Excel demo. It uses ActiveX and will be a lot faster than xlswrite if you need to make multiple writes.
Another option is you could put your data into a table (if you have R2013b or later) and then call writetable().

10 Comments

SQL allows update or add only the required data. For large volumes is the only option.
Dear Image Analyst,
I have tried your ExcelDemo.m on R2014 ans I have MS excel 2007 version.
I am getting the error like below.
Thank you once again.
Did you see the comments at the beginning of the file:
% Uses xlswrite1, available from the File Exchange
% http://www.mathworks.com/matlabcentral/fileexchange/10465-xlswrite1
Download that and it will work.
You have to create an array of data from your measurements structure array.
measurements = regionprops(labeledImage, 'FilledArea', 'EulerNumber', 'Extent', 'AspectRatio');
allFilledAreas = [measurements.FilledArea];
allEulerNumbers = [measurements.EulerNumber];
allExtents = [measurements.Extent];
allAspectRatios = [measurements.AspectRatio];
myData = [allFilledAreas, allEulerNumbers, allExtents, allAspectRatios];
xlswrite1(...........
You say that ultimately you want this "so that it can be used later on, rather than running the process to see the values" . If you want to save these variables simply to recall them later, then it's best you just use save() instead of Excel:
measurements = regionprops(labeledImage, 'FilledArea', 'EulerNumber', 'Extent', 'AspectRatio');
save(matFullFileName, measurements);
Then to recall, use load:
s = load(matFullFileName);
measurements = s.measurements;
Again, Excel would just complicate things.
Did you see where I said to not use Excel? It doesn't seem best for what you want to do.
I do not want to use them later on but just to save them as a doc in excel like the one is doing in your excelDemo using the random values.
I have figured it out how to save it in excel now using your excelDemo but I have one issue now which is:
as for example I have 4 blob information so it will show in in 4 rows but instead it is showing me in one row.
@Image Analyst: I packed the functionality for reading in a simple static class so it can be easily reused.
It will only read contiguous tables and for now only reads tables with columns with a single digit name (A-Z).
I have not benchmarked it against importdata yet.
OK, that's good. I also have a static class with a ton of functions for doing stuff in Excel, like formatting cells, etc. It's attached.

Sign in to comment.

How to save data from matlab GUI edit text box to excel

1 Comment

From GUIDE, App Designer, or inputdlg()?
Have you tried writematrix() or writecell()?

Sign in to comment.

Asked:

on 12 Feb 2015

Commented:

on 1 Jan 2023

Community Treasure Hunt

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

Start Hunting!