convert number to string but keep it the same as it is

2 visualizaciones (últimos 30 días)
Locks
Locks el 19 de Sept. de 2014
Comentada: Star Strider el 20 de Sept. de 2014
Hi,
I have a Matrix containing different time series and I gave them numbers (2000001, 2000002,2000003 etc.) and I would like to convert this numbers into a string. If I use int2Str I get some Kind of matlab representation of this number, but this is not what I am looking for. What I need is at the end a vector as follows:
A=['2000001','2000002','2000003', etc.]
how can I achieve this by a automatic command?
regards

Respuesta aceptada

Star Strider
Star Strider el 19 de Sept. de 2014
In one line:
M = [2000001, 2000002,2000003];
S = strsplit(num2str(M));
produces:
S =
'2000001' '2000002' '2000003'
  4 comentarios
Guillaume
Guillaume el 20 de Sept. de 2014
strsplit (and strjoin) were introduced in version 2013a, if I recall.
Star Strider
Star Strider el 20 de Sept. de 2014
I don’t remember when it arrived.
In its absence, this is as good as it gets:
S = cellstr(int2str(M(:)))
and produces:
S =
'2000001'
'2000002'
'2000003'

Iniciar sesión para comentar.

Más respuestas (2)

Youssef  Khmou
Youssef Khmou el 19 de Sept. de 2014
Editada: Youssef Khmou el 19 de Sept. de 2014
You can achieve that command using transformation from matrix to cells, if M is your matrix :
M=magic(10);
N=size(M);
B=mat2cell(num2str(M(:)),ones(N(1)*N(2),1));
B=reshape(B,N(1),N(2));

Mikhail
Mikhail el 19 de Sept. de 2014
You can convert each number separetely in the for loop.
for i=1:numel(M)
out(:,i)=int2Str(M(i))
end
And you will have out - array of strings Code may have some errors - i didn't try to compile it
  1 comentario
Locks
Locks el 19 de Sept. de 2014
tis results in
222
000
000
000
000
000
123
but that is exactly what I whant to avoid

Iniciar sesión para comentar.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by