Replacing string by start of this string

3 views (last 30 days)
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...:)

Accepted Answer

per isakson
per isakson on 30 Jan 2016
cac = {'AMD','INTEL','ZILOG'
cac = regexprep( cac, '^Z.+$', 'Z80' )
cac =
'AMD' 'INTEL' 'Z80'
'Z80' 'AMD' 'INTEL'
All strings starting with "Z" are replaced by "Z80"
Radoslav Vandzura
Radoslav Vandzura on 31 Jan 2016
Edited: Radoslav Vandzura on 31 Jan 2016
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';
if status == 0
split_cell = 'Iny';
Tcell{i,4} = split_cell;
Thank you :) I appreciate your help and time :)

Sign in to comment.

More Answers (0)


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

Community Treasure Hunt

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

Start Hunting!