Conversion to double from struct is not possible.

27 visualizaciones (últimos 30 días)
Yatin
Yatin el 12 de Mayo de 2015
Comentada: Yatin el 12 de Mayo de 2015
Hello,
When I try to run the following code, it gives me an error at topo_GA with "The following error occurred converting from struct to double:
Error using double
Conversion to double from struct is not possible."
inDir = 'F:\SSVEP study\Data\attnSSVEP\SSVEP_Data\Topography Analysis\Attn Left No Task attn7.14Hz v 11.1Hz\14Hz\';
files = dir([inDir '*.mat']);
outDir = 'F:\SSVEP study\Data\attnSSVEP\SSVEP_Data\Topography Analysis\Attn Left No Task attn7.14Hz v 11.1Hz\14Hz\Final_14Hz\';
topo_GA = [];
for s = 1:length(files)
filename = files(s).name;
x = load([inDir filename]);
topo_GA(s,:) = x;
end
d = mean(topo_GA,1);
figure;topoplot(d, 'biosemi_64.loc');
Can anyone help me to get rid of the error.
Thanks
Yatin

Respuestas (1)

Guillaume
Guillaume el 12 de Mayo de 2015
Editada: Guillaume el 12 de Mayo de 2015
When you do
x = load([inDir filename]); %x is a poor variable name.
x is a structure with fields that are named after the variables in the file. You then assign the structure to topo_GA so topo_GA is also a structure (and as a potential bug, if any of the file you load contains a variable that is not in the other files, the assignment will fail).
You can't take the mean of a structure, hence the error you get. I assume that it's a particular variable in the mat file that you want the mean of, and you'll have to specify it, either when you assign x to topo_GA (best) or when you take the mean:
topo_GA(s, :) = x.somevarname; %less chance of breaking in the future
or
d = mean(topo_GA(s, :).somevarname, 1);
Obviously replace somevarname by the actual name of the variable.
  1 comentario
Yatin
Yatin el 12 de Mayo de 2015
Thank you Guillaume. Adding the variable name did the trick. One of the files int he list had a different variable name which was creating the problem.
Many thanks Yatin

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by