Azzera filtri
Azzera filtri

App Designer: Linking a equation to a Label, I want to show the changing values depending on the inputs given

4 visualizzazioni (ultimi 30 giorni)
I have a function as seen in the image. The parameter values in this function change according to the input values entered.
I want to see the values of each parameter on the function according to the input values entered.
I want to represent these values on an equation image or text. (The user will enter some inputs, and the parameter values will change. I want to see this parameter values in my screen when I enter the inputs) I tried to write the equation in App Designer using app.Label. But I couldn't. And also I wonder whether we can do it with "Interpreter" , "Latex" ? I would be very happy if you could help.
Thanks a lot :))

Risposte (1)

surya venu
surya venu il 3 Apr 2024
Hi,
Here are the steps to do it:
1. Create Text Box for User Input:
  • In App Designer, drag a 'Edit Field' component from the Layout palette onto your app window.
  • Name this component appropriately, such as 'inputValue' or 'userInput', to reflect its purpose.
2. Design the Equation Display:
  • Drag a 'Text Area' component from the Layout palette. This will hold the equation with placeholders for parameter values.
  • Name this component 'equationDisplay' (or a similar name) for clarity.
3. Construct the Equation String:
  • Within the callback function that gets executed when the user enters a value and presses a button (or triggers an update event), construct the equation string dynamically.
  • Use string concatenation to combine the static equation parts with placeholders for the parameters.
Here's an illustrative example assuming the equation is F_H(S) = K / ((T_L * S + 1) * (T_1 * S + 1)) * (1 / (2 * zeta * wn^2)) * exp(-t * S):
function updateEquation(app)
% Get user input from the edit field
userInput = app.inputValue.Value;
% Define parameter values (replace with your actual calculations based on userInput)
K = ...; % Replace with calculation based on userInput
T_L = ...; % Replace with calculation based on userInput
T_1 = ...; % Replace with calculation based on userInput
zeta = ...; % Replace with calculation based on userInput
wn = ...; % Replace with calculation based on userInput
t = ...; % Replace with calculation based on userInput
% Construct the equation string with placeholders and calculated values
equationStr = ['F_H(S) = ', num2str(K), ' / ((', num2str(T_L), ' * S + 1) * (', num2str(T_1), ' * S + 1)) * (1 / (2 * ', num2str(zeta), ' * ', num2str(wn), '^2)) * exp(-', num2str(t), ' * S)'];
% Set the equation display text area with the constructed string
app.equationDisplay.Value = equationStr;
end
4. Call the Callback Function:
  • Link the callback function (e.g., updateEquation) to a button press event or any other appropriate trigger in your app.
  • When the event occurs, the callback function will execute, update the equation string with the latest parameter values, and display it in the text area.
Hope it helps

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by