Can i call variable of another m file in GUI ?

조회 수: 1 (최근 30일)
Jay Patel
Jay Patel 2019년 7월 17일
편집: Adam Danz 2019년 7월 23일
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