How to limit variables in input function?

조회 수: 12 (최근 30일)
Triveni
Triveni 2022년 5월 23일
댓글: Triveni 2022년 6월 4일
I have a function
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun1(1,P_min11 (j), P_max11(j), T, 1);
It perfectly runs.
When I use
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun2(1,P_min11 (j), T, 1);
It perfectly runs.
but when i use
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun3(1,P_min11 (j), ~, T, 1);
It gets error.
please help me.

채택된 답변

Matt J
Matt J 2022년 5월 23일
It does not make sense to have a tilde as an input argument in a function call. Perhaps you meant,
tcfun3(1,P_min11 (j), T, 1);
  댓글 수: 5
Walter Roberson
Walter Roberson 2022년 5월 24일
MATLAB has no way to indicate "missing parameter", with the exception that if a parameter and all following parameters are to be missing then you can leave them all out and the code can use nargin() to tell.
In any case where a missing parameter is followed by a non-missing parameter, the best you can do is create a new class such as MISSING and pass an object of that class, and then have the code use isa() to detect that a parameter was passed but the parameter was that kind of object. This would require that the code be specifically written for your class. Unlike Python, MATLAB does not offer any MISSING indicator built-in
Triveni
Triveni 2022년 6월 4일
Yes, when i sent [] as empty matrix. and add statement within the function
if isempty(idx)
clear idx
end
perfectly work as i want.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by