Error: Conversion to struct from single is not possible
5 ビュー (過去 30 日間)
古いコメントを表示
Hi All,
I had a question regarding inserting data from a cell array into a preexisting structure. The variable "phases" is a 3 x 1 cell array, where each cell is a 1 x 120 single. My code, which is within a loop, looping over multiple files and multiple subjects, below produces the error below.
Data.Encode.AH.High_Theta.Phases = [Data.Encode.AH.High_Theta.Phases, phases{ii,jj}];
Error using horzcat
The following error occurred converting from single to struct:
Conversion to struct from single is not possible.
The structure was made at the start of the code using the following code:
% make the analysis structs
Data.Encode.AH.High_Theta.Phases = struct();
Any ideas on how to do this would be much appreciated! I'm trying to organize and analyze data from multiple subjects, and it would be really nice to be able to do this.
As always, I appreciate the advice!
PAK
0 件のコメント
回答 (1 件)
Walter Roberson
2019 年 2 月 16 日
Data.Encode.AH.High_Theta.Phases
is not a cell array. Instead it is a struct, and phases{ii,jj} is an array of double. The [] operation in your line is trying to put together a struct and an array of double.
Perhaps you should be using something like
Data.Encode.AH.High_Theta(end+1).Phases = phases{ii,jj};
which would create High_Theta as a struct array with field Phases that is an array of single.
2 件のコメント
Walter Roberson
2019 年 2 月 16 日
Storing a multidimensional numeric array is the most efficient storage mechanism that calls for the least memory . For fastest retrieval try to arrange the portions that you will use at any one time to be together in memory .
So for example if hypothetically you do a lot of calculations examining one location across all of the slices then
permute(Your3DArray,[3 1 2])
and reshape that to size(Your3DArray,3) by whatever and then access one column at a time.
But if your work is more image by image rather than across images then leave it in the original order .
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!