How can I get a value from another m file ?

조회 수: 1 (최근 30일)
nero
nero 2015년 12월 6일
댓글: Patrick Miller 2020년 4월 24일
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

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 12월 6일
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
Geoff Hayes
Geoff Hayes 2015년 12월 6일
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 2020년 4월 24일
yes

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

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by