Read a file into app designer with a button and use later with another button
21 次查看(过去 30 天)
显示 更早的评论
Hi,
I am tyring to load a .mat file into an app made with the app designer to be used in a later callback.
I wanted to have one button to load and other buttons to do calculations.
For example, if I want to load a .mat file that has A and B defined.
-------------------------EXAMPLE---------------------
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: LoadFileButton
function LoadFileButtonPushed(app, event)
load('file.mat')
end
% Button pushed function: calculateButton
function calculateButtonPushed(app, event)
A+B
end
end
-----------------------------------------
I wanted the resultant calculation to be A+B using the values of A and B from the original loaded file, however it doesn't seem to store the values of A and B for use with the later callback. Is there anyway to do this?
回答(1 个)
Cris LaPierre
2022-1-11
You need to load your mat file to an app property.
Use the link above to create the property. Let's say you name it S.
Then, in your callback that loads the mat file, you need to use the syntax S = load(___) to load the mat file. Your code, then, might look like this.
% Button pushed function: LoadFileButton
function LoadFileButtonPushed(app, event)
app.S = load('file.mat');
end
Now when you want to use your variable in another callback, just remember they are in the structure app.S, so you might access it as follows (guessing here because we don't know what your mat file has in it). Note that I am assuming the result of the calculation is stored in another app property named calc.
% Button pushed function: calculateButton
function calculateButtonPushed(app, event)
app.calc = app.S.A + app.S.B;
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!