How to extract contents from cell array

10 views (last 30 days)
Weijie
Weijie on 22 Jan 2013
Hi,
I have a cell array that looks like this:
xdata =
[1x51 double]
[1x51 double]
[1x51 double]
[1x51 double]
ydata =
[1x51 double]
[1x51 double]
[1x51 double]
[1x51 double]
which I extracted from Matlab figure files. How can I see the contents in the xdata and ydata?
Thanks a lot for your help

Answers (2)

Cedric
Cedric on 22 Jan 2013
Edited: Cedric on 22 Jan 2013
A few other ways:
>> xdata{:}
or
>> cellfun(@(a)disp(a), xdata)
The content of cell #3, for example, of xdata can be accessed this way:
>> xdata{3}
it is a 1x51 numeric array, whose elements can be indexed, e.g. element #7 of cell #3 can be accessed this way:
>> xdata{3}(7)
  3 Comments
Weijie
Weijie on 23 Jan 2013
Btw, the data shows up in the command window. Any methods to make them show up in the variable editor instead so that I can choose the cells I want?
Cedric
Cedric on 23 Jan 2013
Edited: Cedric on 23 Jan 2013
Actually Matt gave you the answer with the double-click. If you wanted to open cells one by one, you could type the following in the command line:
>> xdata{1}
and see that you are displaying the content of cell #1 of xdata (you can do the same with cells #2 to #4, and also the same with ydata). Then, based on Matt answer, you could type the following in the command window:
>> openvar xdata{1}
and observe that you have the same content, but this time in a spreadsheet. From there you can e.g. cut and paste into Excel.
If you wanted to automatize the export to Excel, you could try to build something based on xlswrite(). If you want to learn more, type the following in the command window:
>> doc xlswrite
but you will have to understand how to deal properly with cell arrays first I guess.

Sign in to comment.


Matt J
Matt J on 22 Jan 2013
One way
openvar xdata ydata
Then click on the cells you want to examine.
  2 Comments
Weijie
Weijie on 23 Jan 2013
Hi I tried ur method and the variable editor pops out with only [1x51 double] [1x51 double] [1x51 double] [1x51 double] in column 1
Any other methods?
Matt J
Matt J on 23 Jan 2013
If you click on those boxes they will open further to show the contents of each cell.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!