Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
i need help for string code
조회 수: 1 (최근 30일)
이전 댓글 표시
this is my code...
clear all
a={'a1' 'a2'};
when i put
a1=1;,a2=2;
disp(a)
result
a = 'a1' 'a2'
but i want my result is
= '1' '2'
what is a problem in my code?
thx for your help
댓글 수: 0
답변 (2개)
Wayne King
2014년 2월 14일
When you write
a1 = 1;
a2 = 2;
You are creating two new variables with values 1 and 2.
What about:
vals = {'1','2'};
newa = strrep(a,a,vals);
disp(newa)
댓글 수: 0
Jos (10584)
2014년 2월 14일
The following might give some insight
a1 = 1 ; a2 = 2 ; A = {a1 a2} ; % declaration
disp(A)
A{1} = 10 ; % change the contents (hidden by the semi-colon)
disp(A)
a1 = 3 % does not change the contents of A
disp(A)
댓글 수: 2
Jos (10584)
2014년 2월 15일
You've lost me … Do you understand the concepts of variables, strings, doubles and cells? If not, take a look at the documentation.
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!