Fucntion input Varargin, value or name.

2 ビュー (過去 30 日間)
Espen Bekkelien
Espen Bekkelien 2018 年 1 月 25 日
回答済み: Steven Lord 2018 年 1 月 25 日
Im trying to load data from an IMU, but I struggle interpeting what i need to use as input for varagi parmater.
Can anyone explane what i have to type inn her,
Imu = loadImu( FileName, varargi(What do i need to write here?))
Example of the code i want to load,
function [ Imu ] = loadImu( FileName, varargi)
%%Arguments
MASTER = 'RA';
option = 'sync';
FsOut = 512;
nVarargs = length(varargin);
for iArg = 1:2:nVarargs
if strcmp(varargin{iArg}, 'Master'), MASTER = varargin{iArg+1};
elseif strcmp(varargin{iArg}, 'option'), option = varargin{iArg+1};
elseif strcmp(varargin{iArg}, 'Fs')
FsOut = varargin{iArg+1};
resampleData = 1;
else error('Invalid argument.');
end
end

採用された回答

Guillaume
Guillaume 2018 年 1 月 25 日
Assuming that the first line of the function is
function [ Imu ] = loadImu( FileName, varargin)
and not
function [ Imu ] = loadImu( FileName, varargi)
as you have written, then you can call it with
Imu = loadImu(somefilename);
%or
Imu = loadImu(somefilename, 'Master', somevalue)
%or
Imu = loadImu(somefilename, 'option', somevalue)
%or
Imu = loadImu(somefilename, 'Fs', somevalue)
or any combination of the extra arguments in any order

その他の回答 (1 件)

Steven Lord
Steven Lord 2018 年 1 月 25 日
I suspect that is a typo in the file, and the second element in the input argument list should be "varargin" not "varargi".
But I don't know what this function expects as its second, third, etc. input arguments. You'd need to ask the person that gave you that code, and ask them to add some help text indicating what it expects and/or can accept. From the if / elseif structure in the code it accepts parameter names 'Master', 'option', or 'fs' but I don't know what the values of those parameters should be.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by