Trying to extract three values in one column based on a value in other column
2 views (last 30 days)
Show older comments
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 :)
0 Comments
Answers (1)
David Hill
on 20 Oct 2022
newMatrix=[yourMatrix(~isnan(yourMatrix(:,1)),1),reshape(yourMatrix(~isnan(yourMatrix(:,2)),2),3,[])'];
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!