Calculations on user input equation
1 回表示 (過去 30 日間)
古いコメントを表示
i want to make calculations on the user input equation which will contain only one variable such as t but when i add or multiply it by any number it gives me a matrix such as shown in this picture.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158501/image.png)
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 11 月 29 日
input() with the 's' option returns a string. You are seeing the result of adding 6 to a string.
You should be having a look at https://www.mathworks.com/help/matlab/ref/str2func.html and at https://www.mathworks.com/help/symbolic/symfun.html
However, you will also need to study Yacc and Lex and similar parsing strategies, and you will probably want to use regexp along the way. You need to study these because you have invented your own input language to represent functions ('5t+3') and you will need to convert that input language into something that MATLAB can understand. You will need to make a lot of decisions about operator precedence such as whether 'a/b/c' means a/(b/c) or means (a/b)/c and whether t--5 is invalid or means minus(t,minus(0,5)). In your invented language, will 'sin x' mean a variable 'sin' multiplied by a variable 'x' or will it be an error or will it mean sin(x) and if it means sin(x) will that be in radians or degrees?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!