필터 지우기
필터 지우기

replace number for specific column in string using (strrep & if)

조회 수: 3 (최근 30일)
Adam Aust
Adam Aust 2014년 4월 17일
댓글: Adam Aust 2014년 4월 17일
i have string 1,2,3,4,5,6,5
4,5,6,8,5,8,6
text string 2*7
at the beginning the 2*7 is strings in text file it is not array so put this text into array to deal with a number (str2double)---->to be [ ]
i want to replace only last column 5 and 6 replacing 1 , 2 (specific column 7)
s1=strrep(st,'5','1');
s2=strrep(s1,'6','2');
we have more than one 5 and 6 number i want replacing only the last column (column 7) ?

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 17일
A=[1,2,3,4,5,6,5;4,5,6,8,5,8,6]
c7=A(:,7)
c7(ismember(c7,5))=1
c7(ismember(c7,6))=2
A(:,7)=c7
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 17일
Do you have a string? a cell array? or a text file?
Adam Aust
Adam Aust 2014년 4월 17일
string ( text) 1,2,3,4,5,6,5 separated by comma, each line rows 7 columns
4,5,6,8,5,8,6

댓글을 달려면 로그인하십시오.

카테고리

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