Borrar filtros
Borrar filtros

Function ontput missed or not assigned

2 visualizaciones (últimos 30 días)
Tonghui Zhang
Tonghui Zhang el 10 de Jun. de 2019
Comentada: Walter Roberson el 10 de Jun. de 2019
Dear all,
I am confronted with a problem now. What I want to do is to formulate a function like
[y1,y2,y3]=f[x1,x2]
Note that the output and input dimensions are constant. Not all outputs will be assigned a value so in Matlab it will report an error. My question is that is there any method that I can assign values to the missed outputs outside when I call the function?
Thanks a lot
  3 comentarios
per isakson
per isakson el 10 de Jun. de 2019
Editada: per isakson el 10 de Jun. de 2019
"is there any method that I can assign values to the missed outputs outside [the function, f ]"
The simple answer is no - afaik.
Tonghui Zhang
Tonghui Zhang el 10 de Jun. de 2019
Editada: per isakson el 10 de Jun. de 2019
Hi,
The function code is as followed
function [y1 y2]=xxx(u)
if u<10
y1=1
else
y2=1
end
end
The error is 'when you are calling function xxx, no value is assigned to y2'

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 10 de Jun. de 2019
function [y1 y2]=xxx(u)
if u<10
y1=1 ;
y2= [] ;
else
y1 = [] ;
y2=1 ;
end
end
  2 comentarios
Tonghui Zhang
Tonghui Zhang el 10 de Jun. de 2019
Thank you for your answer, I know this can solve the problem. My problem is that I don't want to update y2 in this case so, is there any method that I can update the missed output outside the function?
Walter Roberson
Walter Roberson el 10 de Jun. de 2019
No, there is no method to do that. You can use try/catch to handle the error more smoothly, but the error handling will be invoked before the outputs that are present are assigned.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB 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!

Translated by