フィルターのクリア

String handling questions

1 回表示 (過去 30 日間)
Raymond Le
Raymond Le 2011 年 4 月 16 日
I have 2 questions regarding about strings and I would like to get help. 1. How to handle the " ' " in Matlab? - The syntax set_param function is set_param('Model_Name/Block_Name', 'Value', 'data') and I would like to set multiple Block_Name's Value (Block_Name is named as K(i), where i = 1 to N - I tried set_param('Model_Name/K(' & num2str(i) & ')', 'Value', 'data') and set_param('Model_Name/K(' num2str(i) ')', 'Value', 'data') but both failed
2. I have a list of string like [1.21321421412421512312312521131232] and try to convert in to number using num2str() can only convert certain digit, I tried with format long and format longeng but they still cannot handle all of the digits. Is there anyway to handle this?

回答 (2 件)

Paulo Silva
Paulo Silva 2011 年 4 月 16 日
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', 'data')
  2 件のコメント
Raymond Le
Raymond Le 2011 年 4 月 16 日
Thank you very much for helping me out. If I have an array
a = [1 23 42 45 42 54 56 43 45] and I would like to set in to an attribute of a block let set Value which only take single value
I tried:
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', a(i+1))
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', 'a(i+1)')
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', ['a(i+1)'])
but I only get for Value of K(0) = a( , instead of Value of K(0) = 1. Then the program errors out.
Walter Roberson
Walter Roberson 2011 年 4 月 16 日
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', num2str(a(i+1)) )
Or you might find you prefer the style
set_param( sprintf('Model_Name/K(%d)', i), 'Value', sprintf('%d', a(i+1)) )

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


Walter Roberson
Walter Roberson 2011 年 4 月 16 日
The closest you can get to
1.21321421412421512312312521131232
in MATLAB is
1.21321421412421504015810569399036467075347900390625
which is accurate to within
0.0000000000000002220446049250313080847263336181640625
In order to represent 1.21321421412421512312312521131232 more accurately, you need to use the Symbolic Toolbox,
digits(35);
A = sym('1.21321421412421512312312521131232');
However, to use the number meaningfully you would pretty much need to convert the rest of your numbers to symbolic as well as otherwise intermediate calculations might not retain enough accuracy.
  1 件のコメント
Raymond Le
Raymond Le 2011 年 4 月 16 日
Thank you very much.

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by