Adding string to matrix elements

16 次查看(过去 30 天)
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.

采纳的回答

Birdman
Birdman 2018-1-13
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 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by