필터 지우기
필터 지우기

Replacing string by start of this string

조회 수: 3 (최근 30일)
Radoslav Vandzura
Radoslav Vandzura 2016년 1월 30일
편집: Radoslav Vandzura 2016년 1월 31일
Hello All,
would you be so kind, could you advise me, how can i create condition with 'if', when i need replace all columns start with 'something-some string' by other string. For example, I have CPU type:'AMD Opteron 852 Single Core' and I need to replace it by only 'AMD Opteron'....:) Thank you for your help in advance...:)

채택된 답변

per isakson
per isakson 2016년 1월 30일
Hint:
cac = {'AMD','INTEL','ZILOG'
'ZILOG','AMD','INTEL' };
cac = regexprep( cac, '^Z.+$', 'Z80' )
outputs
cac =
'AMD' 'INTEL' 'Z80'
'Z80' 'AMD' 'INTEL'
All strings starting with "Z" are replaced by "Z80"
  댓글 수: 7
per isakson
per isakson 2016년 1월 30일
편집: per isakson 2016년 1월 30일
  • "start with 'something-some string'" &nbsp Why "start", your column contains the full names - or what did I miss ?
  • Where do you have the "more simple name" ?
  • Where do you want to put the new column ?
  • I need more context to help.
Radoslav Vandzura
Radoslav Vandzura 2016년 1월 31일
편집: Radoslav Vandzura 2016년 1월 31일
I resolved it yet by the following way:
for i=1:length(Tcell)
split_cell = strsplit(Tcell{i,4});
status = 0;
switch split_cell{1}
case 'IBM'
status = 1;
split_cell = 'IBM';
case 'AMD'
status = 1;
split_cell = 'AMD';
case 'Intel'
status = 1;
split_cell = 'Intel';
end
if status == 0
split_cell = 'Iny';
end
Tcell{i,4} = split_cell;
end
Thank you :) I appreciate your help and time :)

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

추가 답변 (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