Taking expression input and plotting it within an interval using app designer

1 visualizzazione (ultimi 30 giorni)
I need to take a single variable expression as input from the user and give the plot for the same. I am able to take the expression input and make it a function using inline, but when I go for plotting it within an interval it shows the following error:
Error using inlineeval (line 14)
Error in inline expression ==> x^2 - 11*x + 30
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in inline/subsref (line 23)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
My code for input was:
s = app.EnterHereEditField.Value;
f = inline(s);
and for plotting:
x = -10:.1:10;
y = f(x);
plot(app.UIAxes,x,y);
I am new to matlab app designer, if there's some syntax error please tell. Thanks!

Risposta accettata

Shanmukha Voggu
Shanmukha Voggu il 1 Set 2021
Modificato: Shanmukha Voggu il 2 Set 2021
Hi Aditya,
The error(Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.) is regarding the expression(x^2 - 11*x + 30)
To understand the difference between x.^2 and x^2, let's create a square matrix x
x=[1,2;3,4]
ElementWiseSquare=x.^2 % Every element in the matrix is raised to power "2"
MatrixMultiplication=x^2 % For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix
let's create a row matrix x
x=[1,2]
ElementWiseSquare=x.^2 % Every element in the matrix is raised to power "2"
MatrixMultiplication=x^2 % This statement gives an error because columns in [1,2](first matrix) not equal to rows in [1,2](second matrix)
There can be two fixes for the issue:
1) replace the x^2 in the expression(x^2 - 11*x + 30) with x.^2
2) or make sure x is a square matrix.
refer this for more information.

Più risposte (0)

Categorie

Scopri di più su Control System Toolbox in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by