Can I load a file without single quotes?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Alireza Babaei
el 6 de Sept. de 2022
Comentada: Walter Roberson
el 7 de Sept. de 2022
Dear all,
I am trying to load some files but I get the following error:
Not enough input arguments.
the code I use looks like this:
load(settings_file,'A', 'B');
What are the reasons and potential ways fo fix it?
Another question i swhy the code does not uses single quote sign for the first element (settings_file)? - I am using sb elses files.
another point comming to my mind is: I get the error as I think I cannot find the directory (location where the data is stored).
Any hints?
Thanks!
2 comentarios
Cris LaPierre
el 6 de Sept. de 2022
Can you share the output you get when running the following code in the command window?
which load
Respuesta aceptada
Walter Roberson
el 6 de Sept. de 2022
What you describe suggests to me that you are using someone else's code that has been written in the form of a function. The person who wrote the code expected that the code would be invoked using the function name and the name of a .mat file to load, but you are just running the function (probably by pressing the green Run button.)
You need to pass in the name of a .mat file. For example,
AnalyzeExperiment( 'data20220902.mat')
if the name of the .m file were AnalyzeExperiment and the name of the mat file were data20220902.mat
4 comentarios
Walter Roberson
el 7 de Sept. de 2022
NO! 'A' and 'B' are not files! See for example,
settings_file = 'SomeFileName.mat';
A = 123;
B = 456;
C = 789;
save(settings_file, 'A', 'B', 'C');
ls('-l', settings_file)
whos('-file', settings_file)
clearvars -except settings_file
whos
load(settings_file, 'A', 'B')
whos
A
B
Variables A, B, C are saved in SomeFileName.mat -- a file name that is stored in the variable named settings_file . You can see that the saved file exists and has 265 bytes on disk; you can see that the disk file is named SomeFileName.mat (same as what was stored in the variable.) The file name on disk is not settings_file.mat . You can see that the file has variables named A B C stored inside it.
You can see that I then clear all of the variables except the file name, so A, B, and C are no longer in memory.
You can see that I then load variables A and B from the file; you can see that when I did this, only the named variables A and B got loaded, not any other variables such as C .
A and B are not file names in that syntax: they are variable names. And at that location in the person's code, settings_file is a variable whose name contains the name of the file to load from.
Más respuestas (0)
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!