Borrar filtros
Borrar filtros

Adding string to matrix elements

16 visualizaciones (últimos 30 días)
Banjo
Banjo el 13 de En. de 2018
Respondida: Birdman el 13 de En. de 2018
Hello,
How can I add strings to matrix elements? For example I want to add strings {'A= ' 'B=' 'C=' 'D='} to a matrix Nx4, [i(:) X(:) Y(:) Z(:)].
Matrix with elements:
1 19.632 0.00094518 0.99995
2 23.795 0.0014097 0.99994
3 28.334 7.4669e-05 1
4 3.012 0.0010539 0.99965
5 14.704 0.00065175 0.99996
to become:
A=1 B=19.632 C=0.00094518 D=0.99995
A=2 B=23.795 C=0.0014097 D=0.99994
A=3 B=28.334 C=7.4669e-05 D=1
A=4 B=3.012 C=0.0010539 D=0.99965
A=5 B=14.704 C=0.00065175 D=0.99996
Thank you.

Respuesta aceptada

Birdman
Birdman el 13 de En. de 2018
Use strcat.
B=string(A);
C={'A=','B=','C=','D='};
for i=1:size(A,2)
D(:,i)=strcat(C{i},B(:,i));
end

Más respuestas (0)

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