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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by