필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by