필터 지우기
필터 지우기

Adding string to matrix elements

조회 수: 16 (최근 30일)
Banjo
Banjo 2018년 1월 13일
답변: Birdman 2018년 1월 13일
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