Potencial Matlab Bugs with keyword close
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I stumbled across the blow problem.
let's say I generated the below matrix and save to d:
close = rand(10, 10);
cd 'D:/';
save close close
then I use above in a funcion
function result = testClose()
cd 'D:/'
load close;
pclose = close; %now pclose = 1 which is not the value I loaded, seems the
%close is the keyword close instead of the value I loaded
end
As I understand, in the context of the above function ,the close should be the value I loaded from D drive instead of the keyword close, and if I run the "pclose = close" again in the command window, everything works as expected. This should be a bug.
Please advise.
0 comentarios
Respuestas (1)
Image Analyst
el 7 de Mayo de 2013
Editada: Image Analyst
el 7 de Mayo de 2013
Now hold on there. I hesitate to declare something a bug when (1) someone overwrites a built-in function like "close()", or (2) doesn't use the functions properly. This is how you should do it:
function test
randomValues = rand(10, 10)
save('close.mat', 'randomValues');
% Now recall
testClose
function result = testClose()
storedStructure = load('close.mat');
pclose = storedStructure.randomValues
result = pclose;
Of course it works perfectly fine if you do it like you're supposed to.
3 comentarios
Walter Roberson
el 7 de Mayo de 2013
The difficulty is not with it being a keyword. The difficulty is that you used the closure form of "function", with an "end" statement matching the "function" statement. When you do that, MATLAB assumes that there will not be any values "poofed" into existence.... such as by using the command form of "load". You have
load close
If you had changed that to functional form,
data = load('close');
close = data.close;
then you would not have seen the problem. Likewise, Image Analyst assigns to "close" before the load, and that is sufficient to tell MATLAB to use "close" as an array name instead of as a command.
Ver también
Categorías
Más información sobre Variables 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!