Using Length and Find
조회 수: 9 (최근 30일)
이전 댓글 표시
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));
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!