필터 지우기
필터 지우기

Stuck on this MATLAB question

조회 수: 2 (최근 30일)
Sara Maria El Oud
Sara Maria El Oud 2017년 8월 23일
댓글: Star Strider 2017년 8월 23일
I'm supposed to write a code on MATLAB that solves this problem.
21855372, 21397898, 21303234, 21849704, 21647943, 21485234, 21825033
Take the last three digits of these numbers above and divide them by 1000. Then find arithmetic average of the numbers obtained.
  댓글 수: 3
Sara Maria El Oud
Sara Maria El Oud 2017년 8월 23일
I'm not really sure how to make it into a function that I can run to produce the output which is the arithmetic average. I used the command 'num2str' to extract the last 3 digits from the numbers, I've divided them all by 1000 and I tried to take the average however I think the way I'm supposed to do it is I'm supposed to turn it into a function that I can run. I'm kind of new to MATLAB and its frustrating because this is an easy question I just don't know how to solve it via this program. Help would be much appreciated!

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

답변 (2개)

itend
itend 2017년 8월 23일
% input your values
x = 21855372
x1 = 21397898
x2 = 21303234
x3 = 21849704
x4 = 21647943
x5 = 21485234
x6 = 21825033
%take the last 3 digits
y = num2str(x)
yout = str2num(y(6:8))
y1 = numstr(x1)
yout1 = str2num(y1(6:8))
etc.
%divide each by 1000 and find mean
(y/1000 + y1/1000 + yn/1000...) / (7)
That should do it. Let me know if you have any other questions!

Jan
Jan 2017년 8월 23일
편집: Jan 2017년 8월 23일
Start with
x = [21855372, 21397898, 21303234, 21849704, 21647943, 21485234, 21825033];
Taking the last 3 digits is the same as the remainder if you divide by 1000. The mod or rem command will help here. But if you divide these numbers by 1000 afterwards, both together is the same as the fractional part after the division by 1000.
Now creating the arithmetic mean is not hard. sum might help or what about using the mean command? Try it and ask a specific question in case of problems.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by