필터 지우기
필터 지우기

Access inputs from app designer in the MATLAB script.

조회 수: 35 (최근 30일)
Sakethram
Sakethram 2024년 4월 19일
편집: Pavan Sahith 2024년 4월 29일
I'm currently trying to make an app using App Designer in MATLAB, and I'm facing a challenge with integrating user input from one of the tabs into my MATLAB script.
I aim to gather user input, store it in the base workspace, and then utilize these inputs for calculations within my MATLAB script.Ultimately, I intend to display the calculated results back to the user within the corresponding tab of my app.
For example lets consider something like this
The user adjusts slider values, clicks a button, and expects to see the calculated results in the output section of the app.
Any help or suggestions would be greatly appreciated.

채택된 답변

Pavan Sahith
Pavan Sahith 2024년 4월 19일
편집: Pavan Sahith 2024년 4월 29일
I see that you are trying to achieve seamless integration of user input from your App Designer application into your MATLAB script.
You can do that by defining the Button Callback Function in App Designer. You can refer to this code snippet to get started :
  • This function will capture user inputs from sliders, store these inputs in the 'base workspace', invoke an external MATLAB script to perform calculations, and finally, display the calculated results back in the app.
function ButtonPushed(app, event)
% Retrieve slider values
a = app.Slider.Value;
b = app.Slider2.Value;
% Assign these values to the base workspace
assignin('base','a_value',a);
assignin('base','b_value',b);
% Call the external MATLAB script that performs the calculation
MATLABScript; % Ensure this script is on the MATLAB path or current folder
% Retrieve the calculated result from the base workspace
c = evalin('base', 'c');
app.OutputLabel.Text = num2str(c);
end
  • Here's an example script that demonstrates how to access the stored inputs, carry out a calculation (in this example, multiplication), and then save the result back to the 'base workspace':
a_value = evalin('base', 'a_value');
b_value = evalin('base', 'b_value');
% Perform the calculation
c = a_value * b_value;
% Assign the result back to the base workspace
assignin('base', 'c', c);
  • This method uses the ‘assignin’ and ‘evalin’ functions to facilitate communication between your app and the MATLAB script, ensuring that user inputs are effectively utilized and the results are accurately displayed within your app.
You can refer to the following MathWorks documentation to know more about the 'assignin' and 'evalin'
Hope this information helps you in getting started.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by