Bug about saving a variable
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everybody,
i am experiencing a very strange bug in saving a variable.
Supposing variable name is "xxxxx"
if i execute the instruction
save filetarget xxxxx (which should save the xxxxx variable in the filetarget.mat file)
and then i execute
load filetarget
i receive the following error message: Error using ==>load Unable to read MAT-file C:\....filetarget.mat File may be corrupt
but if i create a variable with a shorter name, that is
x=xxxxx
and then i execute save filetarget x and then load filetarget
everything works...
what can it be??
Thanks in advice!!!!
2 commentaires
Daniel Shub
le 19 Déc 2011
It works fine on my system. Are your variables really only 5 characters long?
Walter Roberson
le 19 Déc 2011
Could you show us the actual variable name you are having problems with?
Which MATLAB version are you using, and which MS Windows version?
Réponses (3)
Naz
le 19 Déc 2011
x=2;
yourfile='name.mat'; %saves in the current directory
save yourfile x
load yourfile
Strange... I don't get an error when using variable xxxxx. Maybe matlab has an issue with the path where you want to save it? Try saving it in the current directory first.
Try using this set:
save(yourfile, 'xxxxx');
new=load(yourfile);
where the 'new' variable will be a struct containing your variable xxxxx. To access it, you need this reference:
newVarible=new.xxxxx;
4 commentaires
Walter Roberson
le 19 Déc 2011
I'm pretty sure that is not true, Naz.
save yourfile x
is taking advantage of command / function duality such as is described briefly by Steve at http://www.mathworks.com/matlabcentral/newsreader/view_thread/51623
save yourfile x
would be treated as
save('yourfile','x')
which would save to the file named yourfile.mat
If you examine the save() documentation at http://www.mathworks.com/help/techdoc/ref/save.html you will see that in each case where command/function duality is used, the filename given is treated literally rather than being evaluated. For example "save test.mat" does not attempt to extract the field named "mat" from the structure variable "test" and use the value of the field as the file name.
Jose Jeremias Caballero
le 19 Déc 2011
Hello.
>> xxxxxxx=rand(3);
>> save filetarget xxxxxxx
>> clear all
>> whos
>> load filetarget
>> whos
Name Size Bytes Class Attributes
xxxxxxx 3x3 72 double
>> display(xxxxxxx)
xxxxxxx =
0.4898 0.7094 0.6797
0.4456 0.7547 0.6551
0.6463 0.2760 0.1626
0 commentaires
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!