Why not adding space between words

3 visualizaciones (últimos 30 días)
Zeynab Mousavikhamene
Zeynab Mousavikhamene el 28 de En. de 2020
Comentada: Zeynab Mousavikhamene el 29 de En. de 2020
strcat('Scale Factor = ',num2str(table2array(T(min(find(find_groups==k)),'scalefactor'))))
and the output is like:
'Scale Factor =0.65'
I need to add the space between = and 0.65. Using above code does not add the space. Any idea/solution?
  1 comentario
Guillaume
Guillaume el 29 de En. de 2020
Please note in Walter's answer how he simplified the horror that is:
table2array(T(min(find(find_groups==k)),'scalefactor')))
to
T.scalefactor(find(find_groups==k,1)))
Use proper table indexing,
table2array(Atable(rows, 'variablename')) %() indexing on a table returns a table
is simply
Atable.variablename(rows) %. indexing returns the content of the table
%or
Atable{rows, 'variablename'} % {} indexing returns the content of the table
and
min(find(something))
is simply
find(something, 1) %get the first element only

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 29 de En. de 2020
Try fprintf()
theNumber = table2array(T(min(find(find_groups==k)),'scalefactor')); % Whatever...but don't use num2str()
fprintf('Scale Factor = %.2f.\n', theNumber);
  6 comentarios
Guillaume
Guillaume el 29 de En. de 2020
If you don't put any restriction on the format length, then matlab won't truncate the input. So
sprintf('Name = %s', theName) %no limit to 2 characters
would work.
If you want a minimum field width of 2 characters but more if required, then
sprintf('Name = %2s', theName) %No . in the format string. Minimum field width of 2, padding with spaces if required
Zeynab Mousavikhamene
Zeynab Mousavikhamene el 29 de En. de 2020
Thank you @Image Analyst and @Allen and @Guillaume. If you post separately I can vote for your posts.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 29 de En. de 2020
For character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form feed. For cell and string array inputs, strcat does not remove trailing white space.
  2 comentarios
Zeynab Mousavikhamene
Zeynab Mousavikhamene el 29 de En. de 2020
so what would you suggest to do?
Walter Roberson
Walter Roberson el 29 de En. de 2020
strcat({'Scale Factor = '}, num2str(T.scalefactor(find(find_groups==k,1))))

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 29 de En. de 2020
If you're using a release that supports string arrays, you can simplify this a bit if you trust MATLAB to do "something reasonable" when combining your text and numeric data.
x = 0.65;
S = "Name = " + x

Categorías

Más información sobre Logical 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