필터 지우기
필터 지우기

Can I load a file without single quotes?

조회 수: 3 (최근 30일)
Alireza Babaei
Alireza Babaei 2022년 9월 6일
댓글: Walter Roberson 2022년 9월 7일
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