structure to cell conversion

4 views (last 30 days)
SUSHMA MB
SUSHMA MB on 2 Apr 2015
Edited: Stephen23 on 2 Apr 2015
I have a structure file with multiple arrays i.e., struct size, and each strut has three different field variables, such as x, y coordinates and cost. Now i want to change into cell. I have tried with 'struct2cell' but in this i am only getting the size of each field variables, and its not displaying any value. ex: val(:,:,1) =
[7x1 double]
[7x1 double]
[7x1 double]
This is what output im obtaining after converting it into cell, only size of the variable, but no values.

Answers (1)

Stephen23
Stephen23 on 2 Apr 2015
Edited: Stephen23 on 2 Apr 2015
Actually the variable val does contain your data, but this is just how MATLAB displays data when it is still inside a cell array. Do not get confused between what MATLAB displays and the data itself: these are two completely different things: this is true for any computer data and any computer program!
Let me demonstrate by creating a simple cell array:
>> A = {[12,34],'bob',{[9;8;7],'mouse'}};
>> A
A =
[1x2 double] 'bob' {1x2 cell}
But this does not mean that all of my data has "disappeared", or that it has been turned into [1x2 double]. It is simply MATLAB giving a summary of what kind of data is inside the cell array, but not showing the data itself. If you want to see your original data, then you need to extract it from the cell array:
>> A{1}
ans =
12 34
>> A{2}
ans =
bob
>> A{3}
ans =
[3x1 double] 'mouse'
Note how the last example uses nested cell arrays:
>> A{3}{1}
ans =
9
8
7

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!