Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Renaming str variables based on conditions

Asked by susan

susan

on 30 Mar 2012
Accepted Answer by Jan Simon

Jan Simon

Hello,

I have a list of Str variables (listed in 1158 columns)

{A} ans =

Columns 1 through 10
    'eyeo'    'eyec'    'ESTR'    'TSTR'    'Co20'    'RT  '    'TEND'    'TSTR'    'Co01'    'RT  ' ....

Is there a quick way to 1) Change 'TSTR' to a new str variable that depends on the very next variable eg. Column 4 becomes 'TSTRCo20'. Column 5 remains the same. Column 8 becomes 'TSTRCo01'. 2) Similarly change 'RT' to reflect the variable that preceded it. eg. column 6 becomes 'RTCo20' and column 9 becomes 'RTCo01'.

Thank you!

1 Comment

Jan Simon

Jan Simon

on 31 Mar 2012

Are you talking about strings or variables?
It would be easier to create an answer, if you post a complete example, which can be copied&pasted with input and wanted output. "{A} ans = Columns 1 through 10 'eyeo' ..." is not useful.

susan

susan

Products

No products are associated with this question.

4 Answers

Answer by Jan Simon

Jan Simon

on 31 Mar 2012
Accepted answer
A = {'eyeo', 'eyec', 'ESTR', 'TSTR', 'Co20', 'RT  ', ...
     'TEND', 'TSTR', 'Co01', 'RT  '};
index = find(strcmp(A, 'TSTR'));
A(index) = strcat(A(index), A(index + 1));
index = find(strcmp(A, 'RT  '));
A(index) = strcat(deblank(A(index)), A(index - 1));
>> A = {'eyeo', 'eyec', 'ESTR', 'TSTRCo20', 'Co20', 'RTCo20', 'TEND', 'TSTRCo01', 'Co01', 'RTCo01'}

0 Comments

Jan Simon

Jan Simon

Answer by Sean de Wolski

Sean de Wolski

on 30 Mar 2012

FAQ

0 Comments

Sean de Wolski

Sean de Wolski

Answer by susan

susan

on 30 Mar 2012

Sorry, But I think your answer is missing..

0 Comments

susan

susan

Answer by susan

susan

on 30 Mar 2012

Anyone?

0 Comments

susan

susan

Contact us