Can I load a file without single quotes?

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 Comments

Can you share the output you get when running the following code in the command window?
which load
sure, here it is:
which load
built-in (C:\Program Files\MATLAB\R2020b\toolbox\matlab\general\load)

Sign in to comment.

 Accepted Answer

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 Comments

Walter,
thanks for the reply.
You got it correctly. I am using sb else's code which is a function with inputs and outputs.
I think one reason is: I do not have the data files 'A' and 'B',
but I do not understand the 'setting_files.' what is this?
In the syntax of load() the 'A' and 'B' name variables to be loaded from the file.
When you run the person's code you need to pass in the name of the file to load, using either a single-quoted string such as 'data7.mat' or a double-quoted string such as "data7.mat"
We do not have enough context to say what the data in the file represents, what size or data type it needs to be; all we know at the moment is that it needs a variable named A and a variable named B in the file.
Thanks!
I understand, I do not have the 'A' and 'B' files, so first I need to find them and then run it.
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!