Can I load a file without single quotes?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Cris LaPierre
2022-9-6
Can you share the output you get when running the following code in the command window?
which load
采纳的回答
Walter Roberson
2022-9-6
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 个评论
Walter Roberson
2022-9-7
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!