Adding string to matrix elements
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Birdman
le 13 Jan 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
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!