Add missing rows to the table without loop

2 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 10 月 29 日
回答済み: Akira Agata 2019 年 10 月 30 日
Attached is the table that I need to add missing rows to it. As you can see there is radius 25 and 33. I need to add radii from 0 to 35 and for radii other than 25 and 33 I want all columns (except radius) to be zero. I need it to be general because 25 adn 33 are not fixed and for the next batch other radii might be nonzero. I need to check radii from 0 to 35 and if they are not existing in the table, add radius to this table and make the zero columns for the rest.
Here is what I have now:
Capture.JPG
and I need to be like this:
Picture2.jpg
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 29 日
I seen an entry at 34 but not at 33 ??
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 10 月 29 日
@Walter Roberson sorry I meant row 33. I made the second table in excel and content of row 34 should be at row 33.

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

採用された回答

Akira Agata
Akira Agata 2019 年 10 月 30 日
Like this?
% Original table
Tbefore = array2table([0 25 12 12 0.08; 0 33 1 1 0.0051],...
'VariableNames',{'time','radius','GroupCount','sum_cell_count','perhexagon'});
% Create output table (all element = 0)
maxRadius = 35;
Tafter = array2table(zeros(maxRadius+1,5),...
'VariableNames',{'time','radius','GroupCount','sum_cell_count','perhexagon'});
Tafter.radius = (0:maxRadius)';
% Find corresponding rows in Tafter for each Tbefore's row
[~,loc] = ismember(Tbefore.radius, Tafter.radius);
% Allocate each Tbefore's row to appropriate position in Tafter
Tafter(loc,:) = Tbefore;

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by