Based on Column 3 values how to get specific column 1 values?

조회 수: 1 (최근 30일)
raghavendra kandukuri
raghavendra kandukuri 2018년 10월 23일
댓글: jonas 2018년 10월 24일
I have 3 columns of data coming from excel, Please find attached txt file, for instance in the attached txt file when column C is '0', i would like to get the value of column A at that point and the two more values above it i.e 2301,2300,2244 in the attached file.

채택된 답변

jonas
jonas 2018년 10월 23일
편집: jonas 2018년 10월 24일
fid = fopen('sample.txt')
out = textscan(fid,'%f%f%f','headerlines',1);
fclose(fid)
A = cell2mat(out);
id0 = find(A(:,3) == 0);
idc = [id0,id0-1,id0-2];
idc = unique(idc)
idc(idc<1) = [];
A(idc, 1)
ans =
2244 2300 2301
works for multiple zeros as well
  댓글 수: 6
raghavendra kandukuri
raghavendra kandukuri 2018년 10월 24일
Yup, worked. Thank you Jonas

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by