Variable Number of Arguments

조회 수: 2 (최근 30일)
Abdul Hanan Wali
Abdul Hanan Wali 2022년 6월 22일
댓글: Image Analyst 2022년 6월 22일
following is a function which unable to run in my matlab. Kindly repair the problem and tell me.
function out = print_num(format, varagin)
out = ' ' ;
argindex = 1;
skip = false;
for ii = 1: length(format)
if skip
skip = false;
else
if format(ii) ~= '%'
out(end+1) = format(ii);
else
if ii + 1> length(format)
break;
end
if format(ii+1) =='%'
out(end+1) ='%';
else
if argindex >= nargin
error(' not enough input arguments');
end
out = [ out num2str(varagin{argindex},format(ii:ii+1))];
argindex = argindex +1;
end
skip = true;
end
end
end
end
  댓글 수: 1
Image Analyst
Image Analyst 2022년 6월 22일
What problem? You forgot to tell us what the problem is.
Don't call your variable "format" since that's a built-in function and can't be used as a variable name. Call it "userFormat" or something else.
And you also forgot to tell us how you called the function. How many arguments did you pass in and what were they? If you pass in, say 8 arguments, how do you parse them into separate variables? Are you expecting variables in a certain order?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 6월 22일
The special keyword is varargin not varagin

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by