Can i call variable of another m file in GUI ?

3 次查看(过去 30 天)
Hello everyone,
i am designing a GUI for bellhop acoustic Toolbox, I m begineer in GUI designing. I wrote a program that can take few parameters as a input from user and run bellhop acoustic tool. I am wondering can i call variable of the another m file to GUI ? for example. If i want to take frequency as input parameter from user and put that user input frequency value to another m file and run bellhop when i press RunBellhop button ?
I am not sure how can i bind the variable of another m file to GUI ? Here I attach a screenshot of GUI and rough m file of GUI.
P.S. I am taking frequency input from user(GUI), writing that to another .m file and when i click on Run Bellhop button it should run below code
%=====================%
% Run Bellhop %
%=====================%
wbellhopenvfil('munkp',case_title,source_data,surface_data,ssp_data,bottom_data,options);
bellhop munkp
and plot the output in space provided :
%=====================%
% Reading output %
%=====================%
figure(2)
subplot(2,1,1)
counter = counter + 1 ; figure(counter)
plot( c , depths ), box on, grid on, view(0,-90)
xlabel('Sound speen (m/s)')
ylabel('Depth (m)')
title('Supply profile to bellhop')
subplot(2,1,2)
switch output_option
case '''C'''
plotshd( 'munkp.shd' ), box on, hold on
plot(rati, zati)
plot(rbty,zbty)
%plotssp( 'munkp' )
hold off
case '''E'''
plotray( 'munkp' ), box on, hold on
plot(rati, zati)
plot(rbty,zbty)
hold off
case '''R'''
plotray( 'munkp' ), box on, hold on
plot(rati, zati)
plot(rbty,zbty)
hold off
case '''IB'''
plotshd( 'munkp.shd' ), box on, hold on
plot(rati, zati)
plot(rbty,zbty)
%plotssp( 'munkp' )
hold off
otherwise
disp('Unknown output option.')
end
disp('done.')
Thanks in advance.
bellhopGUI.m
  4 个评论
Adam Danz
Adam Danz 2019-7-23
Nice work! Here are some recommendations
  1. use str2double instead of str2num https://www.mathworks.com/matlabcentral/answers/52243-why-str2double-is-preferred-over-str2num
  2. Unless 'test3.mat' is changed during the use of the GUI, just import that data once and use persistent variables (see block of code below).
% *not tested
persistent freq X %any other variable in the file that's needed
if isempty(freq)
data = load('test3.mat','freq','X');
freq = data.freq;
X = data.X;
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by