Can this way of defining and using a global variable work?

조회 수: 3(최근 30일)
alpedhuez
alpedhuez 2022년 6월 20일
댓글: Stephen23 2022년 6월 21일
I have main.mlx, plot1.m, and plot2.m. plot1.m and plot2.m is called from main.mlx, get data from 'main.mlx, create plots, and save plots. I want to define a folder that these plots will be saved.
I think of using a global variable to define the folder.
I say, at main.mlx
global folder
folder = 'C:';
Then I say, at plot1.m,
filename=fullfile(folder, 'plot1.jpg')
exportgraphics(t,filename)
Will this work?
  댓글 수: 4
Stephen23
Stephen23 2022년 6월 21일
Passing input arguments is more efficient and more robust than using global variables:

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

답변(0개)

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by