Borrar filtros
Borrar filtros

How to use variable of function in the main program

2 visualizaciones (últimos 30 días)
Adam
Adam el 2 de Ag. de 2014
Comentada: dpb el 2 de Ag. de 2014
Hi all,
I have a main program Main.m. In the main I call a function [a,b,c]=func(data), I would like now to use the output a in the Main.m. how can I do it ?
Thanks for the help.

Respuestas (1)

dpb
dpb el 2 de Ag. de 2014
Editada: dpb el 2 de Ag. de 2014
... I call a function [a,b,c]=func(data),...
So, then you have a in the calling workspace (as well as b and c); so you just reference them as any other variable. Presuming, of course, that func doesn't error when called with data.
% script continues from above...
[a,b,c]=func(data);
fprintf('Asuitableformatstring',a) % display the result variable a or any other use
...
  4 comentarios
Star Strider
Star Strider el 2 de Ag. de 2014
... speaking of which, using sprintf or fprintf might also eliminate some frustration.
dpb
dpb el 2 de Ag. de 2014
good catch...and also a chuckle... :)

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by