Filter löschen
Filter löschen

call on rows in order from arrays of different sizes

1 Ansicht (letzte 30 Tage)
john gutsch
john gutsch am 1 Feb. 2018
Kommentiert: john gutsch am 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.

Akzeptierte Antwort

Jos (10584)
Jos (10584) am 1 Feb. 2018
My idea:
  1. Convert A and B into cell arrays (each row becomes a cell)
  2. Merge into a single cell array
  3. Sort based on first value
  4. Send each cell
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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by