How can I get a value from another m file ?

Hi , Lets say I have the following m file
function y = f1(x)
y = exp(x);
title = 'graph 1';
end
how can I access the variable (title) in my main m file ? for example using the title for a plot in my main file

Respuestas (1)

Geoff Hayes
Geoff Hayes el 6 de Dic. de 2015
nero - return title as an output parameter from your call to the function
function [y,title] = f1(x)
Although, would the title always be 'graph 1', or could it be something different?

3 comentarios

nero
nero el 6 de Dic. de 2015
Editada: Geoff Hayes el 6 de Dic. de 2015
and how would I call it in my other m file ?
because im getting the following error
Undefined function or variable 't'.
Error in test (line 18)
value=t
where test is my main function and I did what you suggested ( function [y,t] = f1(x) ) but I changed title in to t
In your main m file, you would call the function as
[y,t] = f1(x);
passing your x into this function and obtaining the output parameters y and t (the title). How are you attempting to call the function now?
Patrick Miller
Patrick Miller el 24 de Abr. de 2020
yes

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Dic. de 2015

Comentada:

el 24 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by