필터 지우기
필터 지우기

How can I format a large cell of data into one big column underneath a (predeclared) title?

조회 수: 2 (최근 30일)
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!

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 11월 7일
편집: Shubham Gupta 2019년 11월 7일
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
Lance Raju
Lance Raju 2019년 11월 7일
Thank you, I seem to be getting a neater matrix, but I get an error with the line:
my_storage_cell = mat2cell(my_storage_mat2, ones(size(my_storage_mat,1),1),ones(size(my_storage_mat,2)),1);
It says: 'Error using mat2cell
Input arguments, D1 through D2, should be vectors.'
I'm a bit confused as to what this means
Shubham Gupta
Shubham Gupta 2019년 11월 7일
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));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by