Borrar filtros
Borrar filtros

String handling questions

1 visualización (últimos 30 días)
Raymond Le
Raymond Le el 16 de Abr. de 2011
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?

Respuestas (2)

Paulo Silva
Paulo Silva el 16 de Abr. de 2011
set_param(['Model_Name/K(' num2str(i) ')'], 'Value', 'data')
  2 comentarios
Raymond Le
Raymond Le el 16 de Abr. de 2011
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 el 16 de Abr. de 2011
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)) )

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 16 de Abr. de 2011
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 comentario
Raymond Le
Raymond Le el 16 de Abr. de 2011
Thank you very much.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by