필터 지우기
필터 지우기

String handling questions

조회 수: 4 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by