I need help with this logic array

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 Comments

You've posted enough questions that by now you should have worked out how to format your posts correctly. Use the {}Code button!
Looking at all your questions, it looks to me that your way of solving your homework is to throw something at the wall and see what sticks. Spending more time thinking about what you're doing would avoid writing such nonsense as:
GetHighScores = (1:end)
onTime = noTraffic(true), gasEmpty(false);
Jan
Jan on 9 Oct 2017
Edited: Jan on 11 Oct 2017
@Blair: This is your 15th question now. Others and I gave some comments to tell you, that you are not using the forum properly. Posting all your very basic homework questions will not help you in this way. The code you are posting looks rather random and it seems like you did not get the idea of a structured programming yet.
The goal of this forum is to solve Matlab problems, and you have problems while you are using Matlab. But your problems do not concern Matlab itself, but splitting a question into logical parts, using the available information and identify, how they can be used to obtain the wanted output.
The line
GetHighScores = (1:end)
is not meaningful inside the function with the same name. Although you have all required parts for the solution already, the last step of combining them correctly is missing:
meetsThreshold = gamesScores(gameScores > minScore);
You are working with Matlab for at least 24 days. And something is going completely wrong. I would really like to help you, as many others here in the forum also. But if you proceed to ask in the current way, your questions will be ignored soon.
I'm convinced that you have to learn how to solve the questions by your own. In the current phase, posting the solutions of these very basic problems will not teach you, how to analyze a question and formulate the solution in Matlab.
The contents of the questions, you are working on, looks strange: For Matlab all these arrays and conditions are numbers only. The formulation of the questions are as confusing as possible by focusing on the names of the variables and their meaning. Perhaps this is not the right approach for you to learn Matlab.
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.
Use the logical array highscores as an index into scores.

Sign in to comment.

Answers (0)

Asked:

on 9 Oct 2017

Commented:

on 6 May 2023

Community Treasure Hunt

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

Start Hunting!