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
James Browne
James Browne 2022년 1월 11일
Thankyou. This looks like the right dirction.
However, I wanted to load in a struct, so when I do the following
VXLOW = app.out.VXLOW;
I get the error that "Dot indexing is not supported for variables of this type."

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

답변 (1개)

Cris LaPierre
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

카테고리

Help CenterFile 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!

Translated by