I need help with this logic array

4 次查看(过去 30 天)
Blair Hall
Blair Hall 2017-10-9
评论: Kavisha 2023-5-6
The instructions are "Row array gameScores contains all player scores. Construct a row array highScores that contains all player scores greater than minScore. Hint: meetsThreshold is a logic array that indicates which elements in gameScores are greater than minScore. Ex: If gameScores is [2, 5, 7, 6, 1, 9, 1] and minScore is 5, then highScores should be [7, 6, 9]."
function highScores = GetHighScores(gameScores, minScore)
% gameScores: Array contains all player scores
% minScore: Scores greater than minScore are added to highScores
meetsThreshold = (gameScores > minScore); % Logic array indicates which
% elements are greater than minScore
GetHighScores = (1:end)
% Construct a row array highScores containing all player scores greater than minScore
highScores = GetHighScores([meetsThreshold]);
end
  4 个评论
Carl
Carl 2017-10-11
Hi Blair. As other users have stated, a more holistic approach is probably better. If you haven't done so already, I highly recommend taking the MATLAB Onramp training. Having a good grasp on the basics will save you time in the long run.
Kavisha
Kavisha 2023-5-6
Use the logical array highscores as an index into scores.

请先登录,再进行评论。

回答(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