How to change data into something else?

I have a set of data {1-001,1-002,1-003....1-054} how do I take the data and produce something like this {1-N1,1-T1,1-N2,1-T2,1-N3,1-T3....1-N54,1-T54}.

4 comentarios

Walter Roberson
Walter Roberson el 26 de Feb. de 2014
Those are strings? Are the numbers always consecutive? Are they always 3 digits? Is the number before the "-" always "1" ?
andrew
andrew el 28 de Feb. de 2014
yes they are strings and yes the numbers are consecutives some start with 2-, 3-,4- etc
Star Strider
Star Strider el 28 de Feb. de 2014
Does:
1-001 become 1-N1, 1-T1,
1-002 become 1-N2, 1-T2, ...?
andrew
andrew el 28 de Feb. de 2014
yup that is correct:
1-001 become 1-N1, 1-T1,
1-002 become 1-N2, 1-T2

Respuestas (1)

Star Strider
Star Strider el 28 de Feb. de 2014
There may be move elegant and efficient solutions, but this works. You can experiment with the Data2 statement to get the sort of output you want. I organised it as columns for convenience in troubleshooting the code.
Data = {'1-001','1-002','1-003','1-054','2-054','3-054'}
for k1 = 1:size(Data,2)
str = Data{k1};
strptx = strsplit(str, '-');
strvct = str2double(strptx);
Data2{k1,:} = sprintf('%d-N%d, %d-T%d\n',strvct,strvct);
end
char(Data2)

La pregunta está cerrada.

Preguntada:

el 26 de Feb. de 2014

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by