Discussion:
[Scilab-users] Optimization
FIXED-TERM Nacer Mohamed Ikbal (ETAS/ESY)
2018-10-25 13:53:02 UTC
Permalink
Hi,

I have a simple task to split a element of a matrix into rows where remaining columns are duplicated. I have achieved that with loops.
I am sure there is an efficient way to do it using matrix functions. Can you please help?

The data contains both numbers and strings
the column 6 and 7 has equal numbers of elements delimited by '~'


Given Matrix

1 2 3 4 5 a~b~c~d 111~222~333~444
4 5 6 7 6 e~f~g~h~i 555~666~777~888~999
8 9 10 11 12 j~k~l~m 112~223~334~445
.........
.........

Output after processing

1 2 3 4 5 a 111
1 2 3 4 5 b 222
1 2 3 4 5 c 333
1 2 3 4 5 d 444
4 5 6 7 6 e 555
4 5 6 7 6 f 666
4 5 6 7 6 g 777
4 5 6 7 6 h 888
4 5 6 7 6 i 999
8 9 10 11 12 j 112
8 9 10 11 12 k 223
8 9 10 11 12 l 334
8 9 10 11 12 m 445
..........
..........
Mit freundlichen Grüßen / Best regards

Mohamed Ikbal Nacer

Engineering of Systems (ETAS/ESY)
Tel. +49 711 3423-0 | Fax +49 711 3423-300 | fixed-***@etas.com<mailto:fixed-***@etas.com>
CRETE Denis
2018-10-25 16:30:35 UTC
Permalink
Hello
Is this any better ?
Out=[];
for im=1:3,
alpha=tokens(M(im,6));
numbers=tokens(M(im,7));
for jm=1:size(alpha,'r'),
Out=[Out;[M(im,1:5),alpha(jm),numbers(jm)]];
end;
end;

Note : I dont know of any repeat_vector_string function that would be useful to eliminate the inner loop: Out=[Out; [ repeat_vector_string(M(im,1:5),size(alpha)),alpha,numbers]]
(equivalent of kronecker operator for strings...)

HTH
Denis

De : users [mailto:users-***@lists.scilab.org] De la part de FIXED-TERM Nacer Mohamed Ikbal (ETAS/ESY)
Envoyé : jeudi 25 octobre 2018 15:53
À : ***@lists.scilab.org
Objet : [Scilab-users] Optimization

Hi,

I have a simple task to split a element of a matrix into rows where remaining columns are duplicated. I have achieved that with loops.
I am sure there is an efficient way to do it using matrix functions. Can you please help?

The data contains both numbers and strings
the column 6 and 7 has equal numbers of elements delimited by '~'


Given Matrix

1 2 3 4 5 a~b~c~d 111~222~333~444
4 5 6 7 6 e~f~g~h~i 555~666~777~888~999
8 9 10 11 12 j~k~l~m 112~223~334~445
.........
.........

Output after processing

1 2 3 4 5 a 111
1 2 3 4 5 b 222
1 2 3 4 5 c 333
1 2 3 4 5 d 444
4 5 6 7 6 e 555
4 5 6 7 6 f 666
4 5 6 7 6 g 777
4 5 6 7 6 h 888
4 5 6 7 6 i 999
8 9 10 11 12 j 112
8 9 10 11 12 k 223
8 9 10 11 12 l 334
8 9 10 11 12 m 445
..........
..........
Mit freundlichen Grüßen / Best regards

Mohamed Ikbal Nacer

Engineering of Systems (ETAS/ESY)
Tel. +49 711 3423-0 | Fax +49 711 3423-300 | fixed-***@etas.com<mailto:fixed-***@etas.com>
Loading...