Recreating a multiport switch with code
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Nishitha Ayyalapu
2013 年 10 月 15 日
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
その他の回答 (1 件)
Walter Roberson
2013 年 10 月 15 日
[count, idx] = histc(currenttime, control_table(:,1));
datastream = control_table(idx, 2);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Import and Management についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!