Not enough input arguments
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
function [out]=loadrpc(filename, mnchs, flag)
% mnchs: array, the selected channels to be read.
% if empty, read all data
% flag: the same as Matlab fopen's MACHINEFORMAT
% 'l': ieee-little-endian, such as NT
% 'b': ieee-big-endian, such as UNIX
% default is 'l'
%
% example:
% y=loadrpc('test.rsp'); %read all data
% z=loadrpc('test.rsp', [2, 10 20]); %read channel: 2, 10, and 20
%
if (nargin==1)
mnchs='';
flag='l';
mnchs_n=0;
elseif ((nargin==2) & ~isempty(mnchs))
flag='l';
mnchs_n=max(size(mnchs));
elseif ((nargin==3) & ~isempty(mnchs))
mnchs_n=max(size(mnchs));
else
mnchs='';
mnchs_n=0;
end
fid=fopen(filename, 'r', flag);
if (fid == -1)
out=0;
return;
end
Repurposing some old code written 20 years ago. This code represents the first part of a function used to read the values of .rsp files (binary format; time history data). 'Not enough input arguments' error ocurs at the line: fid=fopen(filename, 'r', flag);
2 comentarios
Torsten
el 20 de En. de 2022
You can not simply run this function "loadrpc".
You must call it with appropriate input arguments for filename, mnchs and flag.
Respuestas (1)
Image Analyst
el 20 de En. de 2022
Wow - bad, fragile code. Not robust at all. For example it does not check filename to see if it's empty. And does check with isfile(filename) to see if it exists before trying to open it.
Anyway, what did you pass in for filename, mnchs, and flag when you called the function?
You didn't just press the green run triangle without assigning values to those variables did you? Because it obviously needs a filename to call fopen(). It can't be just null.
2 comentarios
Image Analyst
el 20 de En. de 2022
Yes, of course. That defines the function but not the variables. So, in your main program when you get to this line:
[out]=loadrpc(filename, mnchs, flag)
if you haven't defined filename, mnchs, flag, what is it supposed to use for those values? Just make up something? What if you wanted 'test.dat', 5, and 'b' and you didn't pass those in? Is it okay if the program makes up and uses "bogus.dat", 9, and 'l" instead? That might not do what you want. So you have to tell it what you want.
So, like
[out]=loadrpc('mydata.dat', 4, 'b');
or whatever you want/need.
Ver también
Categorías
Más información sobre Variables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!