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
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.

请先登录,再进行评论。

回答(1 个)

dpb
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
Name Size Bytes Class Attributes EEG 1x1 4048648 struct
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
Name Size Bytes Class Attributes EEG 1x1 4048648 struct
EEG = struct with fields:
setname: 'Continuous EEG Data' filename: 'eeglab_data.set' filepath: '' pnts: 30504 nbchan: 32 trials: 1 srate: 128 xmin: 0 xmax: 238.3047 data: [32×30504 single] icawinv: [] icasphere: [] icaweights: [] icaact: [] event: [1×154 struct] epoch: [] chanlocs: [] comments: [6×769 char] averef: 'no' rt: [] eventdescription: {[2×29 char] [2×63 char] [2×36 char] ''} epochdescription: {} specdata: [] specicaact: [] reject: [1×1 struct] stats: [1×1 struct] splinefile: [] ref: 'common' history: '' urevent: [1×154 struct]
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
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
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×2 struct array with fields:
labels X
out(1)
ans = struct with fields:
labels: 'ABC' X: [1 2 3]
out(2)
ans = struct with fields:
labels: 'DEF' X: [1 2 3]
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))
Unable to resolve the name 'data.Fp1'.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Labeling and Segmentation 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by