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?
댓글 수: 2
답변 (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!