Adding string to matrix elements

21 views (last 30 days)
Banjo
Banjo on 13 Jan 2018
Answered: Birdman on 13 Jan 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.

Accepted Answer

Birdman
Birdman on 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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!