call on rows in order from arrays of different sizes

1 回表示 (過去 30 日間)
john gutsch
john gutsch 2018 年 2 月 1 日
コメント済み: john gutsch 2018 年 2 月 2 日
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.

採用された回答

Jos (10584)
Jos (10584) 2018 年 2 月 1 日
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
  1 件のコメント
john gutsch
john gutsch 2018 年 2 月 2 日
That was exactly what I needed, thanks for the great answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by