フィルターのクリア

Trying to extract three values in one column based on a value in other column

1 回表示 (過去 30 日間)
Terra
Terra 2022 年 10 月 20 日
回答済み: David Hill 2022 年 10 月 20 日
Hi,
I have two columns one is 1, NaN, NaN,NaN,NaN,NaN,NaN,2,NaN,NaN,NaN,NaN,NaN,NaN,,3 (...to 11, and then back to 1..2..etc.). The second column has numeric values at the second, fourth and sixth NaN position of each "set". I want to have these values from the second column in a row "beside" the corresponding number from column 1. For example 1; 10,16,18. 2; 5, 6,8 ...... to then ultimately have all the "1s" in a group with their three values, all the 2s in a group etc.
I am struggeling with this. I have tried doing a for loop i=1; while i<size(data, 1), then if data(:,1) == i , i = i + 6; else i = i + 1. It doesnt work.
Could someone give me some ideas or help please :)

回答 (1 件)

David Hill
David Hill 2022 年 10 月 20 日
newMatrix=[yourMatrix(~isnan(yourMatrix(:,1)),1),reshape(yourMatrix(~isnan(yourMatrix(:,2)),2),3,[])'];

カテゴリ

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