Need to fill out skipped rows in a matrix

1 回表示 (過去 30 日間)
Davis Philip Reina-Guerra
Davis Philip Reina-Guerra 2022 年 10 月 7 日
I have a data analysis code which spits out values by experimental trials 1-10. The problem is that some trials (by design) do not produce a value, meaning some of the data is "complete" and some is "partial". I need help filling out the partial data with the missing trials so that all data matrices are 10x2 and it is straightforward to perform operations on them.
I think this example illustrates my point best. How do I approach this? Even just links to relevant documentation would help a ton, I am still fairly new to the MATLAB universe

採用された回答

Davide Masiello
Davide Masiello 2022 年 10 月 7 日
編集済み: Davide Masiello 2022 年 10 月 7 日
Take this example
complete = [(1:10)',rand(10,1)]
complete = 10×2
1.0000 0.2436 2.0000 0.5726 3.0000 0.6157 4.0000 0.2325 5.0000 0.1763 6.0000 0.8804 7.0000 0.3370 8.0000 0.7356 9.0000 0.7864 10.0000 0.1872
partial = [sort(randperm(10,6))',rand(6,1)]
partial = 6×2
1.0000 0.5511 2.0000 0.4288 4.0000 0.1780 7.0000 0.1619 8.0000 0.5053 10.0000 0.8134
You can apply the following to you dataset.
missing_n = ~any(partial(:,1) == 1:10,1)
missing_n = 1×10 logical array
0 0 1 0 1 1 0 0 1 0
newpartial = zeros(size(complete));
newpartial(missing_n,:) = [find(missing_n)',nan(nnz(missing_n),1)];
newpartial(~missing_n,:) = partial;
partial = newpartial
partial = 10×2
1.0000 0.5511 2.0000 0.4288 3.0000 NaN 4.0000 0.1780 5.0000 NaN 6.0000 NaN 7.0000 0.1619 8.0000 0.5053 9.0000 NaN 10.0000 0.8134
  1 件のコメント
Davis Philip Reina-Guerra
Davis Philip Reina-Guerra 2022 年 10 月 7 日
Thank you!! This is exactly what I needed

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by