How can I format a large cell of data into one big column underneath a (predeclared) title?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lance Raju
am 6 Nov. 2019
Kommentiert: Shubham Gupta
am 7 Nov. 2019
My goal is to generate some kind of 'tabular' representation of data and then output this filtered dataset to a new file. Something that looks like:
Foo Bar Fubar
0 0 0
1 100 50
................(54321 lines later)
.......................................
54321 0 1441
The only way I can obtain the data though is through a 1x1 struct containing 2 regions of 155x1 cell, 1 called titles, 1 called data.
So, what I do is...
titles = transpose(theStruct.theTitles(index));
*Index is the already known set of indexes I'm pulling Foo/Bar/Fubar titles from
my_storage = titles; %foo, bar, fubar header titles
my_storage{2,1} = transpose(theStruct.theData{6,1}); %foo data
my_storage{2,2} = transpose(theStruct.theData{7,1}); %bar data
my_storage{2,3} = transpose(theStruct.theData{8,1}); %fubar data
What I end up getting though is just the cell arrays containing all doubles in 'theData{6,1}'/'theData{7,1}' in 'my_storage', so it looks like:
Foo Bar Fubar
54321x1 double 54321x1 double 54321x1 double
Foo, Bar, and Fubar are ALL cells as well too, which seems like it 'might' be problematic to write to files with.
I played around with 'my_storage(:,1)' (colon operator) to try to modify it to write its contents to all data underneath, but it didn't work based off what I tried.
How could I have the entire cell underneath Foo, Bar, and Fubar (the 54321x1 double cell) turned into just a large column of data? Is there a built-in, simple method that doesn't involve a raw for-loop?
Thanks!
1 Kommentar
Akzeptierte Antwort
Shubham Gupta
am 7 Nov. 2019
Bearbeitet: Shubham Gupta
am 7 Nov. 2019
Try this:
my_storage = titles; %foo, bar, fubar header titles
my_storage_mat = [transpose(theStruct.theData{6,1}),... % foo
transpose(theStruct.theData{7,1}),... % bar
transpose(theStruct.theData{8,1})]; % fubar
my_storage_cell = mat2cell(my_storage_mat,ones(size(my_storage_mat,1),1),ones(size(my_storage_mat,2)),1);
my_storage = [titles;my_storage_cell];
You should get what you need, let me know if you have doubts.
2 Kommentare
Shubham Gupta
am 7 Nov. 2019
I am sorry I made error with the brackets position. Try this:
my_storage_cell = mat2cell(my_storage_mat,ones(size(my_storage_mat,1),1),ones(size(my_storage_mat,2),1));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!