Another function that don't function
조회 수: 1 (최근 30일)
이전 댓글 표시
I had some help getting to this point, but anyways here's the problem for the function we need. I can't seem to get it to give me a complete answer. If i mess with the indexs I can get it to where it'll give me more than one answer, but they'll mostly be zeros. Help,please.
- Write a MATLAB function that takes the input of a list of scores and gives the output of the number of scores that are between 0 and 79.
function n = score(list)
Test the function for the following input lists:
- List 1 of 30 scores: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43,98,36,87,22,61,19,69,26,82,89,99,71,59,49,64
- List 2 of 5 scores: 35, 18, 99, 74, 85
Here's where I'm at
function n = score(list)
index = 1;
% looping through the array
for i = 1:numel(list)
% if the number is between 0 and 79 then putting it in array n
if list(i) >= 0 && list(i) < 80
n(index) = list(i);
index = 1;
end
end
end
댓글 수: 0
답변 (1개)
Walter Roberson
2021년 3월 7일
n(index) = list(i);
index = 1;
What benefit is there in resetting the index to 1 when it is already 1?
What benefit is there in storing the values when you are just asked to count them?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!