the user will be asked to input number which is good but the problem is how can I make that as numbers and letters for example 2x and put it in matrix

1 回表示 (過去 30 日間)
A=Input ('enter the number') user add it but I need it to accept both letters and numbers
  2 件のコメント
John D'Errico
John D'Errico 2021 年 6 月 10 日
2x is NOT valid as a formula/expression in MATLAB. And that means you would need to parse the input, inserting multiplication symbols as needed.
Dilovan Rafeeq
Dilovan Rafeeq 2021 年 6 月 10 日
Seems understandable but how can I do that with matlab

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2021 年 6 月 10 日
This is a really complicated task, which is prone to bugs. How do you want to treat "2x" compared to "x2"? If "x" is a variable, "x2" can be a variable also. Or it can mean "x * 2". There is no clear and clean way, to distinguish this. Therefore Matlab uses the * as multiplication operator and omitting it in "2x" is no valid syntax.
If you want to write a really intelligent parser, make sure to publish the results as PhD or sell it at least to Google for their AI resarch.
Are you sure, that this job is required to solve your problem?

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by