How to limit variables in input function?

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.

 Respuesta aceptada

Matt J
Matt J el 23 de Mayo de 2022
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 comentarios

Triveni
Triveni el 23 de Mayo de 2022
And when,
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun3(1,~, P_max11(j), T, 1);
And P_max and P_min with different Names.
It is invalid syntax to put a ~ as an input parameter.
If you want to indicate a placeholder that is needed for position, but whose value is going to be ignored, then pass in any value there. Traditonal is [] such as
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun3(1, [], P_max11(j), T, 1);
Note: there is no way for MATLAB to tell the difference between the idea that the value you pass in such as [] is a "real" [] that is to be treated as valid input, compared to it being there as a place-holder. The exception to this is that if all of the trailing inputs are to be indicated as missing, you can omit them, such as
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun3(1, [], P_max11(j), T);
and by checking nargin(), MATLAB would be able to tell the difference between that (with the final input missing) compared to
[P_max1(j), ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~] = tcfun3(1, [], P_max11(j), T, []);
where the final input is (in context) intended to indicate that an "actual" [] is to be passed in
Triveni
Triveni el 24 de Mayo de 2022
When i replace variable with [], it goes as empty variable or real variable. I want to send the data which not exists.
Walter Roberson
Walter Roberson el 24 de Mayo de 2022
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 el 4 de Jun. de 2022
Yes, when i sent [] as empty matrix. and add statement within the function
if isempty(idx)
clear idx
end
perfectly work as i want.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2022a

Preguntada:

el 23 de Mayo de 2022

Comentada:

el 4 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by