I am having a horzcat error while I try to create a structure from smaller structures.
5 ビュー (過去 30 日間)
古いコメントを表示
I am having a structure with the name data (1x1) another structure (1x16) that has data inside. and finally a table (1x254) with times values.
I confused If I have bad instruction of how those 3 should be forming a structure to laser use them in EEGLAB with BIOSIG plugin (import the final structure using the pop_biosig command).
my guides to create the structures (1x16) this command
chanlocs = struct('labels', {data.Fp1,data.Fp2, data.F7, data.F3, data.F4, data.F8, data.T3, data.C3, data.C4,data.T4, data.T5, data.P3, data.P4, data.T6, data.O1, data.O2}, ...
'type', {'EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG'}, ...
'ref', {char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty}, ...
'theta', {-18, 18,-54,-39,39,54,-90,-90,90,90,-126,-141,141,126,-162,162}, ...
'radius', {0.511,0.511,0.511,0.333,0.333,0.511,0.511,0.256,0.256,0.511,0.511,0.333,0.333,0.511,0.511,0.511}, ...
'X', {0.95,0.95,0.587,0.673,0.673,0.587,6.12e-17,4.4e-17,4.4e-17,6.12e-17,-0.587,-0.673,-0.673,-0.587,-0.95,-0.95}, ...
'Y', {0.309,-0.309,0.809,0.545,-0.545,-0.809,0,0.719,-0.719,0,0.809,0.545,-0.545,-0.809,0.309,-0.309}, ...
'Z', {-0.0349,-0.0349,-0.0349,0.5,0.5,-0.0349,0.999,0.695,0.695,-0.999,-0.0349,0.5,0.5,-0.0349,-0.0349,-0.0349}, ...
'sph_theta', {18,-18,54,39,-39,-54,-0.0349,90,-90,-0.0349,126,141,-141,-126,162,-162}, ...
'sph_phi', {-2,-2,-2,30,30,-2,90,44,44,-90,-2,30,30,-2,-2,-2}, ...
'sph_radius', {0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0}, ...
'urchan',{char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty}, ...
'value',{char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty});
then use
[data t chanlocs]
to create this structure to use on EGGLAB.
however I receive the horzcat error which I can seemed to find a way to over come it.
Any ideas to resolve or have further questions to the problem please let me know.
Kostas
7 件のコメント
dpb
2023 年 8 月 6 日
"(1x1) x (1x16) should be possible in all cases (ie. structure, arrays, etc.)."
No. It would never be possible other than to combine the two whatevers as a cell array with each cell containing the corresponding object.
MATLAB objects are all regular and the only way any can be catenated is that the types and sizes are commensurate in all respects. Anything else other than stuffing disparate stuff into cells in a cell array is simply not possible.
Walter Roberson
2023 年 8 月 6 日
note by the way that the [] operations does not support scalar expansion.
回答 (1 件)
dpb
2023 年 8 月 6 日
編集済み: dpb
2023 年 8 月 6 日
OK, I found where the tutorial <eeglab_data.set> had been uploaded to GitHub so could get a peek at it without downloading the entire package..
Answers won't let attach a file without the approved .mat extension, so I renamed to conform; it's still the same file content, just without the EEG Lab .set extension.
whos -file eeglab_dataset.mat
So, it is a MATLAB struct -- that we probably had guessed...just what does it comprise of?
Let's load it and see...
load eeglab_dataset % can dispense with the "-mat" since is using the .mat
whos EEG % see what it is...
OK, it is just a single struct; which one of those defined we saw in the description?
EEG
So there ya' go...you don't append stuff; you put it in the .set .mat struct file as another member -- the chanlocs data here is an empty array; you would assign yours there, it would appear.
NOTA BENE: Some of the field content are themselves struct -- observe 'reject', 'stats', 'urevent'. Also note that 'urevent' is a struct array, not just a single struct. That's how they deal with the mismatch in sizes; EEG Lab has to know how to deal with these struct fields that are structs within the struct; you tell it what they are by adhering to the given naming convention for each.
I think there's a lot more flexibility to load individual defined structs than just loading a single .set file as the example uses, but it'll take learning your way around the package to find out all the ways things can be done.
But, you don't catenate stuff together as you were trying; that's just not legal MATLAB syntax for the most part except for the few specific things that can be made to match as Walter showed.
3 件のコメント
dpb
2023 年 8 月 7 日
編集済み: dpb
2023 年 8 月 7 日
chanlocs = struct('labels', {data.Fp1,data.Fp2, data.F7, data.F3, data.F4, data.F8, data.T3, data.C3, data.C4,data.T4, data.T5, data.P3, data.P4, data.T6, data.O1, data.O2}, ...
'type', {'EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG'}, ...
'ref', {char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty}, ...
'theta', {-18, 18,-54,-39,39,54,-90,-90,90,90,-126,-141,141,126,-162,162}, ...
'radius', {0.511,0.511,0.511,0.333,0.333,0.511,0.511,0.256,0.256,0.511,0.511,0.333,0.333,0.511,0.511,0.511}, ...
'X', {0.95,0.95,0.587,0.673,0.673,0.587,6.12e-17,4.4e-17,4.4e-17,6.12e-17,-0.587,-0.673,-0.673,-0.587,-0.95,-0.95}, ...
'Y', {0.309,-0.309,0.809,0.545,-0.545,-0.809,0,0.719,-0.719,0,0.809,0.545,-0.545,-0.809,0.309,-0.309}, ...
'Z', {-0.0349,-0.0349,-0.0349,0.5,0.5,-0.0349,0.999,0.695,0.695,-0.999,-0.0349,0.5,0.5,-0.0349,-0.0349,-0.0349}, ...
...
NOTA BENE: In the description of the EEG (.set file) struct with its fields of data including sub-structs like chanlocs, the data are all shown as normal MATLAB numeric arrays, NOT cell arrays. I think you'll need to convert your generation code to use [] instead of {} for the numeric data.
chanlocs = struct('labels', {data.Fp1,data.Fp2, data.F7, data.F3, data.F4, data.F8, data.T3, data.C3, data.C4,data.T4, data.T5, data.P3, data.P4, data.T6, data.O1, data.O2}, ...
'type', {'EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG', 'EEG','EEG','EEG'}, ...
'ref', {char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty,char.empty}, ...
'theta', [-18, 18,-54,-39,39,54,-90,-90,90,90,-126,-141,141,126,-162,162], ...
'radius', [0.511,0.511,0.511,0.333,0.333,0.511,0.511,0.256,0.256,0.511,0.511,0.333,0.333,0.511,0.511,0.511], ...
'X', [0.95,0.95,0.587,0.673,0.673,0.587,6.12e-17,4.4e-17,4.4e-17,6.12e-17,-0.587,-0.673,-0.673,-0.587,-0.95,-0.95], ...
'Y', [0.309,-0.309,0.809,0.545,-0.545,-0.809,0,0.719,-0.719,0,0.809,0.545,-0.545,-0.809,0.309,-0.309], ...
'Z', [-0.0349,-0.0349,-0.0349,0.5,0.5,-0.0349,0.999,0.695,0.695,-0.999,-0.0349,0.5,0.5,-0.0349,-0.0349,-0.0349], ...
...
etc., ...
Read through that description of the EEG and ALLEEG struct in the doc CAREFULLY, looking at the examples shown of sample inputs.
It actually is the Hansel and Gretel trail of breadcrumbs through the forest that gives the needed format to use and the other tutorial file (that I didn't find a link to other than downloading the whole enchilada) is more complex and has these substructs populated for examples.
I see that there are more complicated input patterns discussed using the other tutorial file in line in the discussion that illustrate chanlocs struct being in EEG struct, etc., ...
Once one finally gets to the details, it is pretty straightforward; the ".set" file is just a MATLAB .mat file containing the EEG struct as outlined. Although it appears it can also be saved/read as two files; one the metadata and a second that contains the actual raw data.
Walter Roberson
2023 年 8 月 7 日
Note:
When you use struct() and the data portion associated with a fieldname is a cell array, then struct() creates one structure member for each element of the cell array, with each element of the cell array in turn being assigned as the member contents. When you use a non-cell then the contents are copied to every struct member.
Example,
out = struct('labels', {'ABC', 'DEF'}, 'X', [1 2 3])
out(1)
out(2)
This can lead to code such as
Xvals = [0.95,0.95,0.587,0.673,0.673,0.587,6.12e-17,4.4e-17,4.4e-17,6.12e-17,-0.587,-0.673,-0.673,-0.587,-0.95,-0.95];
Yvals = [0.309,-0.309,0.809,0.545,-0.545,-0.809,0,0.719,-0.719,0,0.809,0.545,-0.545,-0.809,0.309,-0.309];
Zvals = [-0.0349,-0.0349,-0.0349,0.5,0.5,-0.0349,0.999,0.695,0.695,-0.999,-0.0349,0.5,0.5,-0.0349,-0.0349,-0.0349];
thvals = [-18, 18,-54,-39,39,54,-90,-90,90,90,-126,-141,141,126,-162,162];
rvals = [0.511,0.511,0.511,0.333,0.333,0.511,0.511,0.256,0.256,0.511,0.511,0.333,0.333,0.511,0.511,0.511];
N = length(Xvals);
chanlocs = struct('labels', {data.Fp1, data.Fp2, data.F7, data.F3, data.F4, data.F8, data.T3, data.C3, data.C4,data.T4, data.T5, data.P3, data.P4, data.T6, data.O1, data.O2}, ...
'type', repmat({'EEG'}, 1, N), ...
'ref', repmat({''}, 1, N), ...
'theta', num2cell(thvals), ...
'radius', num2cell(rvals), ...
'X', num2cell(Xvals), ...
'Y', num2cell(Yvals), ...
'Z', num2cell(Zvals))
参考
カテゴリ
Help Center および File Exchange で Labeling and Segmentation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!