Variable changes value after using load
古いコメントを表示
I've been writing a script that runs a function with numerous subfunctions and I've been careful to not use global variables. At one point in the main function a few matrices saved as .mat are loaded if they do not exists in the workspace. The strange thing is that a variable of mine: maxnumsource = 2; That is one of the input parameters in that defines in the script that runs the main function changes value and is somehow redefined as maxnumsource = 1; after doing the load command. I wrote out the values of the variable right before and after the load and somehow it's redefined! Now the even stranger thing is that when I changed the name to maxnumsources with the added 's' this didn't happen anymore. So I 'fixed' the problem but I would like to know why this happens so I can avoid this in the future. And before anyone asks: No the loaded variables were not named maxnumsource.
Thanks
4 件のコメント
Dishant Arora
2014 年 6 月 13 日
Attach your code.
dpb
2014 年 6 月 13 日
...loaded variables were not named maxnumsource.
The crystal ball says it was by accident during debugging or testing by a save that inadvertently included the variable.
Execute
whos -file 'yourmatfile'
and see. You could check for how many and which ones were accidentally contaminated automagically by
d=dir('*.mat');
for i=1:length(d)
s=whos('-file',d(i).name,'maxnum*')
if ~isempty(s)
for j=1:length(s)
disp([d(i).name 'contains ' s(j).name]
end
end
end
I'm betting you'll find at least one case...
Elías Heimisson
2014 年 6 月 13 日
dpb
2014 年 6 月 13 日
Told ya'... :)
Easy mistake to make; no problem...
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Variables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!