Hi,
I have researched Matlab. When I use Num2str,
disp (['Iteration ' num2str (it) ': Best cost = ' num2str (Bestcosts(it))]);
it happen a mistake
Error using num2str (line 41)
Not enough input arguments.
Please, help me solve this problem
Thank you

 Respuesta aceptada

Majid Farzaneh
Majid Farzaneh el 26 de Mayo de 2018
Editada: Majid Farzaneh el 26 de Mayo de 2018

1 voto

Hi, Don't use space between num2str and '('. This will work:
disp (['Iteration ' num2str(it) ': Best cost = ' num2str(Bestcosts(it))]);

5 comentarios

per isakson
per isakson el 26 de Mayo de 2018
>> num2str ( 117 )
ans =
117
is ok with R2016a
Majid Farzaneh
Majid Farzaneh el 26 de Mayo de 2018
Editada: Majid Farzaneh el 26 de Mayo de 2018
>> ['test' num2str (117)]
Error using num2str (line 35)
Not enough input arguments.
When you are using num2str alone, yeah, it works. But in this case (in a string matrix) it dosn't work.
>> ['test' num2str(117)]
ans =
test117
per isakson
per isakson el 26 de Mayo de 2018
Correct!
That's might be why I never build strings that way.
str = sprintf( 'Iteration %d: Best cost = %f', it, Bestcosts(it) );
Tran Hoa
Tran Hoa el 26 de Mayo de 2018
Excellent. It is done. Thank you very much Majid Farzaneh.
Majid Farzaneh
Majid Farzaneh el 26 de Mayo de 2018
You're welcome

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Mayo de 2018

Comentada:

el 26 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by