while creating figure based app in MATLAB, how to give callback to another matlab code?

조회 수: 2 (최근 30일)
I am working on to create figure based app, standalone application in MATLAB for plotting graphs from load data.
let me give brief explanation of my work,
There are two push buttons, 'Load data' and 'Plot data' from where I can load data and then it will plot the data in given location like shown in figure.
I have matlab code ready which imports data from excel file and then it plot the data. here my question is Can I callback this matlab code to push buttons and plot the data in GUI?
and if we cannot callback matlab code then how can import all data with 'Load data' push button?

답변 (2개)

Geoff Hayes
Geoff Hayes 2021년 4월 26일
Ashwini - yes, you should be able to use your other MATLAB code depending upon how it is written. You will want it to be a function so that you can pass in the data and/or filename (of the data to import) and pass in the axes handle where you want to plot the data.
  댓글 수: 2
Ashwini  More
Ashwini More 2021년 4월 26일
Thank you @Geoff Hayes,
I got what you are trying to say but can you please give demo as it is giving error as I am missing something.
I have attached my script that I have completed till the moment.
  1. To load the data I want to load this Loaddata .m file but it is giving error as "Too many output arguments."
function Loaddata
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'A7:A33';
Engine_Speed = xlsread(filename,sheet,xlRange);
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'B7:B33';
Engine_Power_ON = xlsread(filename,sheet,xlRange);
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'C7:C33';
Engine_Power_OFF = xlsread(filename,sheet,xlRange);
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'D7:D33';
Gear_One= xlsread(filename,sheet,xlRange);
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'E7:E33';
Gear_Two= xlsread(filename,sheet,xlRange);
filename = 'Power Calculations 37T.xlsx';sheet = 3;xlRange = 'F7:F33';
end
2. To plot the data I want to plot
function PlotData
plot(Gear_One,Engine_Power_OFF,'Linewidth',2,'color','k')
hold on
plot(Gear_One,Engine_Power_ON,'Linewidth',2,'color','b')
hold on
plot(Gear_Two,Engine_Power_OFF,'Linewidth',2,'color','k')
hold on
plot(Gear_Two,Engine_Power_ON,'Linewidth',2,'color','b')
hold off
end
How script will change to import and plot this data with callback function in main script?
I look forward to hearing from you.
Image Analyst
Image Analyst 2021년 4월 26일
For 1., how are you calling it? Evidently you're doing something like
[Engine_Speed, Engine_Power_ON, Engine_Power_OFF, Gear_One, Gear_Two] = LoadData();
If you do that you need to define output arguments:
function [Engine_Speed, Engine_Power_ON, Engine_Power_OFF, Gear_One, Gear_Two] = LoadData()

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


Image Analyst
Image Analyst 2021년 4월 26일
Your pushbutton callback can call other functions. Just make sure the function is in the mlapp or .m file, or on the search path, or in the same folder as your app. It should work then.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by