Extract data from a cell array/struct
古いコメントを表示
Good afternoon,
I have been having this probelm all day and I cannot fix it. I am trying to extract the the 3rd column (WaterCumulativeMass) from each of the cell arrays. The problem I am encountering is that the second cell array only contains the headers and no values (which is correct), so to keep consistancy with the other arrays I blank it. This has the effect of turning the cell array into a Struct which I then convert back into a cell array.
The code which works partially (shown) extracts the data from the third column of cell array but combines it into a single column vector where I would like it as columns like it would normally do in a matrix for anything involving a loop function with counter. If I were to use anything with a counter i.e. ABC(i) = array{i}.data(:,3) it states that the left and right sides are not equal or the dot function is not applicable to this etc.
I have tried extracting the data from the struct format aswell but this again will not work
Can someone help please?
% Partially successful cell array method
CC = mydata_EL;
CC{2} = [];
for i = 3:numel(CC); % Needs to start at 3rd column because of the blanks
ABC = CC{i}.data(:,3)% Does extract 3rd columns. Creates a single vector
%ABC(i) = CC{i}.data(:,3) # Does not work with the counter
end
3 件のコメント
Guillaume
2019 年 7 月 30 日
"I am trying to extract the the 3rd column (WaterCumulativeMass) from each of the cell arrays"
What cell arrays? Your attached mat file has many variables. Note that columns of cell arrays don't have name, so it's unclear what you mean by (WaterCumulativeMass)
"only contains the headers"
headers of what?
"This has the effect of turning the cell array into a Struct"
cell arrays will never turn intro structures unless you specifically use cell2struct to do so. So it's not clear what you're doing.
I'm afraid your explanation is very unclear.
- What is/are the input variable(s)?
- What do you want to do with them?
- Example of desired output?
Richard Rees
2019 年 7 月 31 日
編集済み: Richard Rees
2019 年 7 月 31 日
Eva-Maria Weiss
2019 年 7 月 31 日
Maybe reshape would help? lhttps://de.mathworks.com/help/matlab/ref/reshape.html
But since the number of values of both shapes you've written here is not equal, something else might going wrong...
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!