Can I load a file without single quotes?

3 次查看(过去 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
Cris LaPierre 2022-9-6
Can you share the output you get when running the following code in the command window?
which load
Alireza Babaei
Alireza Babaei 2022-9-7
sure, here it is:
which load
built-in (C:\Program Files\MATLAB\R2020b\toolbox\matlab\general\load)

请先登录,再进行评论。

采纳的回答

Walter Roberson
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 个评论
Alireza Babaei
Alireza Babaei 2022-9-7
Thanks!
I understand, I do not have the 'A' and 'B' files, so first I need to find them and then run it.
Walter Roberson
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)
-rw-r--r-- 1 mluser worker 265 Sep 7 19:40 SomeFileName.mat
whos('-file', settings_file)
Name Size Bytes Class Attributes A 1x1 8 double B 1x1 8 double C 1x1 8 double
clearvars -except settings_file
whos
Name Size Bytes Class Attributes settings_file 1x16 32 char
load(settings_file, 'A', 'B')
whos
Name Size Bytes Class Attributes A 1x1 8 double B 1x1 8 double settings_file 1x16 32 char
A
A = 123
B
B = 456
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by