Conversion to double from struct is not possible.

24 ビュー (過去 30 日間)
Yatin
Yatin 2015 年 5 月 12 日
コメント済み: Yatin 2015 年 5 月 12 日
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

回答 (1 件)

Guillaume
Guillaume 2015 年 5 月 12 日
編集済み: Guillaume 2015 年 5 月 12 日
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 件のコメント
Yatin
Yatin 2015 年 5 月 12 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by