Taking expression input and plotting it within an interval using app designer
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Shanmukha Voggu
2021-9-1
编辑:Shanmukha Voggu
2021-9-2
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!