Replacing string by start of this string

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...:)

 Respuesta aceptada

per isakson
per isakson el 30 de En. de 2016
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 comentarios

Radoslav Vandzura
Radoslav Vandzura el 30 de En. de 2016
But, how can i use it in a cycle for...when i need examine all rows?
per isakson
per isakson el 30 de En. de 2016
??? regexprep handles all rows in one operation. I showed that with two rows.
Radoslav Vandzura
Radoslav Vandzura el 30 de En. de 2016
yes, but i have more types of CPU type....for example I need replace: 'IBM Power6 Model 520 Dual Core'- IBM Power 'Itanium 2 9010 Single Core'-Itanium 'AMD Opteron 8218 Dual Core'-AMD...
I need examine all rows in that column....
per isakson
per isakson el 30 de En. de 2016
Editada: per isakson el 30 de En. de 2016
Can't you add a new line for each
cac = regexprep( cac, '^I.+$', 'Pentium' )
cac = regexprep( cac, '^A.+$', 'Opteron' )
"I need examine all rows in that column...." &nbsp I don't understand
Radoslav Vandzura
Radoslav Vandzura el 30 de En. de 2016
This is my column of CPU Type (not all) and I need each row replace by the more simple name...So, I need do it with 'for', I think....
per isakson
per isakson el 30 de En. de 2016
Editada: per isakson el 30 de En. de 2016
  • "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 el 31 de En. de 2016
Editada: Radoslav Vandzura el 31 de En. de 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';
end
if status == 0
split_cell = 'Iny';
end
Tcell{i,4} = split_cell;
end
Thank you :) I appreciate your help and time :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Centro de ayuda y File Exchange.

Preguntada:

el 30 de En. de 2016

Editada:

el 31 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by