String handling questions
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
Paulo Silva
2011년 4월 16일
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', 'data')
댓글 수: 2
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!