Conversion to double from struct is not possible.
27 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Guillaume
on 12 May 2015
Edited: Guillaume
on 12 May 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.
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!