필터 지우기
필터 지우기

Using Length and Find

조회 수: 5 (최근 30일)
Caroline Prekker
Caroline Prekker 2020년 7월 25일
댓글: Walter Roberson 2020년 7월 25일
I am trying to find the sum of numbers in a matrix by the 4th inning (the data is from multiple softball games) so that I can compare them to see who is in the lead by the 4th inning. I have tried the code below and cannot figure out how to get it to work. The two that aren't working are the oppPtsAfter4 and auPtsAfter4
%Auburn record after all games
auNumWins = length(find(gamePts(:,1)<gamePts(:,2)));
fprintf('Auburn season record: %d-%d\n',auNumWins,auRows-auNumWins)
%Auburn record at the end of the 4th inning
oppPtsAfter4 = length(find(oppPoints,4:8));
auPtsAfter4 = length(find(auPoints,13:17));

답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 25일
When you use a numeric second parameter for find(), then you are controlling the number of reponses you want returned. It does not make sense to put a vector at that point.
Wouldn't you be wanting to look at something like oppPoints(:,4) and auPoints(:,4) ?
auNumWins = length(find(gamePts(:,1)<gamePts(:,2)));
A much more compact way of writing that is
auNumWins = nnz(gamePoints(:,1) < gamePoints(:,2));
  댓글 수: 3
Caroline Prekker
Caroline Prekker 2020년 7월 25일
that portion is also not the problem I am having, that was given to us and works fine. The issue I am having is finding the sum of points after 4 innings of each game by both teams because it is a matrix
Walter Roberson
Walter Roberson 2020년 7월 25일
Is the matrix a list of points per inning? If so then sum(oppPoints(:,1:4), 2) would give the sum for the first 4 innings.
auPoints,13:17
Is your data file set up so that for each game you have a list of 9 values that are opponent runs in one inning, followed by a list of 9 values that are Auburn runs in one inning? If so then it could make sense to access columns 1:4 (the opponent) and 10 to 13 (auburn). However if the data has already been split into two matrices, as hinted by oppPoints and auPoints being different arrays, then it would not appear to make sense to look in columns 10:13 of auburn data.

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

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by