Hello,
Assuming input data are stored in
I = [0,0,0,1; 10, 0, 3, 1;15, 30, 0, 1;18, 0, 45, 0;36, 57, 28, 0];
there might be also a solution using the “sparse” function:

Nb_Dat=size(I);
Time= I(:,1);
ij=[1+ones(Nb_Dat(2),1).*.Time,(1:Nb_Dat(2))'.*.ones(Time)] ;
sp=sparse(ij,I);
// Display full Matrix
full(sp)

and it may be more efficient (?) writing it on a single line:
sp2=sparse([1+ones(size(I,'c'),1).*. I(:,1),(1: 
size(I,'c'))'.*.ones(I(:,1))],I);

HTH.
Denis

De : users [mailto:users-boun...@lists.scilab.org] De la part de Philipp 
Mühlmann
Envoyé : mercredi 12 octobre 2016 14:55
À : Users mailing list for Scilab
Objet : Re: [Scilab-users] inserting data into a bigger matrix

charming...exactly what I need.

2016-10-12 14:45 GMT+02:00 Rafael Guerra 
<jrafaelbgue...@hotmail.com<mailto:jrafaelbgue...@hotmail.com>>:
Hi Philipp,

Does the simple code here below meet the requirements?

I = [0,0,0,1; 10, 0, 3, 1;15, 30, 0, 1;18, 0, 45, 0;36, 57, 28, 0];
ix1=I(1,1);
ix2=I($,1);
ix=ix1:ix2;
M=zeros(length(ix),4);
M(1:$,1) = ix';
M(I(:,1)+1,:)=I;

PS:
It should be easy to adapt it for a general time series consisting of floats 
and constant time-sampling.

Regards,
Rafael

From: users 
[mailto:users-boun...@lists.scilab.org<mailto:users-boun...@lists.scilab.org>] 
On Behalf Of Philipp Mühlmann
Sent: Wednesday, October 12, 2016 2:16 PM
To: International users mailing list for Scilab. 
<users@lists.scilab.org<mailto:users@lists.scilab.org>>
Subject: [Scilab-users] inserting data into a bigger matrix

Dear Scialb users,


how to insert time based data into a pre-defined Matrix without using a 
for-loop?

The data points are not equally spaced in time.


example:
// assuming DATA includes 5 data Points
// each dat Point consists of 4 variable
// first variable = time

//datafile could look like

Time, Var1, Var2, Var3
0, 0, 0, 1
10, 0, 3, 1
15, 30, 0, 1
18, 0, 45, 0
36, 57, 28, 0

Assume that a timestep of 1 second is wanted.

desired result should look like this:

M =
0 0 0 1
1 0 0 0
2 0 0 0
3 0 0 0.
...
10 0 3 1
...
15 30 0 1
...
18 0 45 0
...
36 57 28 0

so "M" is bigger than the original dataset.

Again, I think I could do this using for-loops.
This could be OK for small dataset, but maybe become slow for huge data sets (> 
100'000 data points).

Thanks,
Philipp




Thanks,
Philipp





--
In Kanada is' ka' na' da. Sonst wär' Kanada Jemanda.

There we have the salad.

_______________________________________________
users mailing list
users@lists.scilab.org<mailto:users@lists.scilab.org>
http://lists.scilab.org/mailman/listinfo/users



--
In Kanada is' ka' na' da. Sonst wär' Kanada Jemanda.

There we have the salad.
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to