How can I get cell2struct to work within my for loop? "error using cell2struct, Number of field names must match number of fields in new structure"

1 visualización (últimos 30 días)
I am using a forloop to extract band powers from EEG data. I keep getting errors for the cell2struct funciton I use within my code. I want the output (store) to contain the aspects you can see in the store variable within a structure. The values are provided by the for-loop running function "compute_epoched_bandpower".
I just need to know how to fix the "error using cell2struct, Number of field names must match number of fields in new structure" I keep getting when referring to the line "temp1=cell2struct(temp, fields, 1)".
Any help would be massively appreciated!
dats = ALLEEG;
l = length(dats);
store = struct('setname', EEG.setname,'rel_bp_time_series_bands', rel_bp_time_series.band,'abs_bp_time_series_bands', abs_bp_time_series.band,'rel_bp_time_series_band_mean', rel_bp_time_series.band_mean,'abs_bp_time_series_band_mean', abs_bp_time_series.band_mean);
temp = []
temp1 = struct([])
for i = 1:l
[rel_bp_time_series,abs_bp_time_series ] = compute_epoched_band_power(ALLEEG(:,i));
eeg.setname = EEG.setname(i)
temp = [ rel_bp_time_series.band, abs_bp_time_series.band,rel_bp_time_series.band_mean, abs_bp_time_series.band_mean]
fields = {'rel_bp_time_series_bands','abs_bp_time_series_bands','rel_bp_time_series_band_mean','abs_bp_time_series_band_mean'}
temp1 = cell2struct(temp, fields, 1)
store = [ store temp1 eeg.setname]
end

Respuestas (1)

Stephen23
Stephen23 el 7 de Jun. de 2019
Editada: Stephen23 el 7 de Jun. de 2019
Following the cell2struct documentation, if fields is a four-element cell array and dim is 1 then temp would have to be a cell array with four rows. It is unclear from your description what class the source fields have, but most likely you will need to actually define that four-row cell array, e.g. if the fields are horizontal cell vectors:
temp = [...
rel_bp_time_series.band;...
abs_bp_time_series.band;...
rel_bp_time_series.band_mean;...
abs_bp_time_series.band_mean];
or if they are horizontal numeric vectors:
temp = {...
rel_bp_time_series.band;...
abs_bp_time_series.band;...
rel_bp_time_series.band_mean;...
abs_bp_time_series.band_mean};
or whatever conversion you need to do to create a cell array of size 4x....

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by