フィルターのクリア

Add missing rows to a list in a cell array

2 ビュー (過去 30 日間)
Raúl García Odriozola
Raúl García Odriozola 2023 年 6 月 29 日
I have a cell array with values like this
...
9 [10370;10371;10372]
10 [12933;12934]
11 10001
12 11320
13 [11347;11348]
14 [10362;10363]
17 [12632;12633]
...
And i want to add blank rows for all the missing numbers in the first collumn so it would look like this
...
9 [10370;10371;10372]
10 [12933;12934]
11 10001
12 11320
13 [11347;11348]
14 [10362;10363]
15
16
17 [12632;12633]
...
I have a list of how many items should appear on the first row but i'm having problems finding a way without using a for loop, the list is too big for that.

採用された回答

cdawg
cdawg 2023 年 6 月 29 日
Will this work?
m = {...
9 [10370;10371;10372]
10 [12933;12934]
11 10001
12 11320
13 [11347;11348]
14 [10362;10363]
17 [12632;12633]};
inds = cell2mat(m(:,1));
lastRow = 20;
M = cell(lastRow,2);
M(inds,2) = m(:,2);
M(inds,1) = m(:,1)
M = 20×2 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {[ 9]} {3×1 double} {[ 10]} {2×1 double} {[ 11]} {[ 10001]} {[ 12]} {[ 11320]} {[ 13]} {2×1 double} {[ 14]} {2×1 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
  1 件のコメント
Raúl García Odriozola
Raúl García Odriozola 2023 年 6 月 29 日
Exactly what i wanted, thank you for your help

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by