When I import this function, there is a error when I run this codes.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chris
el 4 de Nov. de 2021
Respondida: Image Analyst
el 4 de Nov. de 2021
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 04-Nov-2021 14:13:03
% Import the file
newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
importfile('gravity_anomaly_.mat')
<Error>
Not enough input arguments.
Error in importfile (line 9)
newData1 = load('-mat', fileToRead1);
1 comentario
DGM
el 4 de Nov. de 2021
It works fine for me.
whos % nothing in the base workspace
importfile('carbig.mat') % load
whos % now there's a bunch of stuff in the workspace
function importfile(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 04-Nov-2021 14:13:03
% Import the file
newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
end
Respuesta aceptada
Steven Lord
el 4 de Nov. de 2021
Is this line:
importfile('gravity_anomaly_.mat')
inside the importfile function or do you run this in the Command Window?
I suspect you called importfile with no input arguments. If that's correct, move that line I quoted above out of the importfile function and use that to call importfile with an input argument.
0 comentarios
Más respuestas (2)
Walter Roberson
el 4 de Nov. de 2021
load() is not documented as being able to accept the -mat option before the file name, so it is possible that in your version (which you did not mention... hint, hint) that the parsing is deciding that the -mat is the first option and that the filename is missing.
0 comentarios
Image Analyst
el 4 de Nov. de 2021
You don't need that function. In fact we usually don't recommend using assignin() anyway. Instead of the importfile() function, which reads the filename into the base workspace, you can simply call load() which will do exactly the same thing:
load('gravity_anomaly_.mat')
Again, there is no need to call that importfile() function from your script at all.
0 comentarios
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!