I'd like to read formula data like '10x+4x+2' in txt. file.
I got this formula from diary function.
diary('value1.txt');
value1
diary off
And I'd like to put '10x+4x+2' into some value.
Like
velocity=10x+4x+2
Could I have some advice?
Thank you.

回答 (1 件)

Star Strider
Star Strider 2017 年 9 月 11 日

0 投票

Try this:
value1 = '10*x+4*x+2';
velocity_fcn = str2func(['@(x) ' value1]);
x = 42;
velocity = velocity_fcn(x)

4 件のコメント

Heisenberg's
Heisenberg's 2017 年 9 月 12 日
Thank you.
But 'value1' is from txt. file.
How can I read txt. file?
Star Strider
Star Strider 2017 年 9 月 12 日
There are several options. See if the fscanf (link) function will do what you want. Also, see Data Import and Export (link) and Low-Level File I/O (link) for a general discussion.
Heisenberg's
Heisenberg's 2017 年 9 月 13 日
I really appreciate!
I will try this!
Star Strider
Star Strider 2017 年 9 月 13 日
My pleasure!
If my Answer helps you solve your problem, please Accept it!

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

カテゴリ

ヘルプ センター および File Exchange で 데이터 가져오기 및 내보내기 についてさらに検索

質問済み:

2017 年 9 月 11 日

コメント済み:

2017 年 9 月 13 日

Community Treasure Hunt

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

Start Hunting!