- Convert A and B into cell arrays (each row becomes a cell)
- Merge into a single cell array
- Sort based on first value
- Send each cell
call on rows in order from arrays of different sizes
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
john gutsch
il 1 Feb 2018
Commentato: john gutsch
il 2 Feb 2018
I have multiple arrays of different dimensions, and I want to send each row from each array as a separate UDP message. The rows in each array are already in the correct order, but I need to send them in an order across the array. For example: A = [1 0 0; 2 0 0; 4 0 0] and B = [3 0 0 0; 5 0 0 0; 6 0 0 0]. The first column is the order that the UDP needs to send at. So we send the first row from A, then the second row from A, then the first row from B, then the third row from A, etc...
I can't combine the arrays because they are different sizes. Any ideas on how to grab the individual rows in order?
I didn't include my code so far because the arrays are imported from CSVs, but I can post everything if that's helpful or my question is unclear.
0 Commenti
Risposta accettata
Jos (10584)
il 1 Feb 2018
My idea:
A = [1 10 ; 2 20 ; 4 40 ], B = [3 30 30 ; 5 50 50]
C = [mat2cell(A,ones(1,size(A,1)),size(A,2)) ; mat2cell(B,ones(1,size(B,1)),size(B,2))] % #1 & #2
[~,ix] = sort([A(:,1) ; B(:,1)]) % #3.1
C = C(ix) % #3.2
% #4
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!