How do you count how many values are in an array until a given number?

조회 수: 6 (최근 30일)
I have an array of values, it starts with integers then some zeros appear before finally more integers and then more zeros. I am looking to find a way to cut the array short before the second set of zeros appear.
The minimum value always occurs in column 5 of the second set of integers so I thought I could find the minimum value and cut if off there, however to do this I need to know how what row this minimum number occurs at. Ive seen in some forums that the find function may be able to be used however I cant get it to work. An extract of my script is posted below.
data = csvread(['groupC0',num2str(i),'.CSV'],6,0);
limit = find(data,min(data(:,5)))
truedata = data(1:limit,3:8);
  댓글 수: 1
Jan
Jan 2013년 4월 24일
The text description of the inputs is not clear. Are you talking about a vector or a matrix? If it is a matrix, do the zero blocks have the same position in each row (or column?)?

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

채택된 답변

Jan
Jan 2013년 4월 24일
x = [1,2,3,4,5,0,0,0,0,4,3,2,4,2,0,0,0,0,4,3,2]; % Does this match your data?!
zeroBlockStart = strfind(x == 0, [false, true]) + 1;
Now you have the indices, where the blocks of zeros start. Does this help already?
  댓글 수: 1
Dave
Dave 2013년 4월 24일
Thanks for your response, it was imported as a matrix but I was only looking for the maximum value in one column. I made it work by using:
data = csvread(['groupC0',num2str(i),'.CSV'],6,0);
[r minloc] = find(data==min(data(:,5)));
truedata = data(1:r,3:8);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by