How to save stats values from matchScans?

조회 수: 2 (최근 30일)
Amrik Sandhu
Amrik Sandhu 2019년 1월 25일
댓글: Amrik Sandhu 2019년 1월 29일
I'm using the matchScans function within a for loop and I want to be able to store the stats values (stats.Score) for each scan but I've found that at the end of the for loop it only saves the score for the last scan and I can't find a way to callback to any previous scores for other scans. This is the code I'm using to try and store the score;
for idx = K(1):K(numMatches)
[transform, stats] = matchScansGrid(currentScan, referenceScan);
Score = [idx stats.Score];
end
I've found that the code below added to the for loop will display the code for each scan but it only displays it and I have no way to save it.
if stats.Score / currentScan.Count < 1.0
disp(['Low scan match score for index ' num2str(idx) '. Score = ' num2str(stats.Score) '.']);
end
Is there a way I can store displayed results in an array or is there another way I can save the score from each scan (rather than just the last scan) in a single array? Thanks in advance.

채택된 답변

Cam Salzberger
Cam Salzberger 2019년 1월 28일
편집: Cam Salzberger 2019년 1월 28일
Hello Amrik,
Yes, your code is close to what you are looking for, but you are replacing the value of Score every loop iteration, rather than appending to it. One common pattern of doing this you might have seen before is this:
Score = [];
for ...
Score = [Score stats.Score];
end
However, I would suggest pre-allocating your array for better performance. And if you are looking to to keep the index as well, you could do this:
Score = zeros(numMatches, 2);
for idx = 1:numMatches
[transform, stats] = matchScansGrid(currentScan, referenceScan);
Score(idx, :) = [K(idx) stats.Score];
end
Alternatively to an array, you could simply save all the stats to a structure array (if you care about anything other than the score).
Also, I'm making assumptions here on what you meant with your loop limits and indexing into K. If that's not correct, feel free to correct it.
-Cam
  댓글 수: 1
Amrik Sandhu
Amrik Sandhu 2019년 1월 29일
Thanks so much. That first bit of code did the job exactly

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by