Multiport switch with code
Ältere Kommentare anzeigen
Hello,
I am trying to create a multiport switch with code. I have a control vector and 40 other vectors stored as one matrix (called data). The control vector denotes which of the 40 data vectors to pass through. All 41 of these vectors (control and 40 data vectors columns) have the same number of elements. So ultimately, I would like to create one vector with chunks from each of the 40 data vectors (dependent on what the control vector specifies). Another user suggested doing this by indexing but I don't completely understand his code (found below). Any help would be greatly appreciated. I'm very new to indexing and could use any information provided.
Thanks in advance.
Btw, this is a sample control stream. My actual one is immense but I have limited it to 20000 elements so a method that does this faster than a for loop (if possible) would be great.
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
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!