Azzera filtri
Azzera filtri

Recreating a multiport switch with code

1 visualizzazione (ultimi 30 giorni)
I have 40 different streams of data (formatted time, value) numbered 1 through 40 and one control stream that selects which data stream to pass through (time, stream id). I'm trying to switch between different streams of data depending on what the control stream says can be passed through. For example, control stream (time, stream id)
0 1
1 3
2 3
3 1
4 1
5 5
6 4
7 9
8 2
9 1
10 1
So for time 0-.9 (assuming resolution is .1) the first data stream should be passed through (select time=0 to .9 from data stream and make it first portion in new stream) then for 1 to 2.9 pass through the data from stream 3 that has a time of 1 to 2.9 and attach it to the end of the new stream, etc. At the end you have one data stream that's made up of parts of the 40 different streams.
This is essentially what a multiport switch does, but I wanted to try and recreate the operation in code. Any help would be greatly appreciated.
Thanks in advance for your help!

Risposta accettata

Nishitha Ayyalapu
Nishitha Ayyalapu il 15 Ott 2013
1.) Store each data stream as a column vector (just the values). Since time stamps for all the streams are starting at 0 and sampled at 0.1 secs (or any units of time), we use indexing to locate the right time interval. Once you do this, you will have 40 column vectors
DatStream1, Datstream2... Datstream40
2.) concatenate all of them into one Matrix of 40 Columns. let us say
DataMatrix
So for example, if you want to access Stream 20 you would access by indexing DataMatrix as:
DataMatrix(:,20)
From here on your code would be
ControlStream = [0 1 1 3 2 3 3 1 4 1 5 5 6 4 7 9 8 2 9 1 10 1];
newStream = [];
startindex = ControlStream(1:2:end);
endindex = startindex+10;
streamNum = ControlStream(2:2:end);
for i = 1:length(startindex)
newStream = [newStream DataMatrix(startindex(i):endindex(i),streamNum(i))];
end
  2 Commenti
Muneer
Muneer il 23 Ott 2013
I apologize for the late response, this is a huge help.
If you notice, the control stream has a value of 0 in it, but there is no 0th stream in my datamatrix. So I'm assuming when a 0 pops up, it won't know what to pass through and it will yield an error. Is there any way to apply a value to all these 0s in the control stream? For example, for every zero that comes up, pass it through and replace it with "NULL" or something in the final stream.
Really appreciate the help.
Muneer
Muneer il 23 Ott 2013
Also,
could you comment on your indexing a little more. I don't completely follow why you called the odd and even elements and added ten.
Thanks

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 15 Ott 2013
[count, idx] = histc(currenttime, control_table(:,1));
datastream = control_table(idx, 2);

Community Treasure Hunt

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

Start Hunting!

Translated by