Help with a basic MATLAB question
이전 댓글 표시
Hey, i'm learning how to use MATLAB and I was confused on what was meant by the question. Can someone explain how I can decompose the number using rem please?
?
댓글 수: 4
Rik
2019년 5월 3일
The task is to turn the number into a vector of its decimal components. So for 864736 you need to find a way to turn that into a vector [8 6 4 7 3 6]. Your teacher wants you to use the rem function to find those values.
You should read the documentation (type doc rem in the command window).
Since the ID has a relatively small length I would propose a different method: turn it into a char array (see sprintf) and then cast it back to a double.
Jacob
2019년 5월 3일
Rik
2019년 5월 5일
Please don't delete your question text. It is extremely rude to get free help first and then remove the potential for any future reader to benefit as well.
Rena Berman
2019년 5월 13일
(Answers Dev) Restored edit
답변 (1개)
Guillaume
2019년 5월 3일
2 개 추천
Given a positive integer, e.g. x = 749623, you're supposed to decompose it into a vector of digits, for my example y = [7, 4, 9, 6, 2, 3].
- What is the remainder of 749623 / 10 ?
- What is the remainder of 74962 / 10 ?
- What is the remainder of 7496 / 10 ?
- etc.
That should be enough for you to understand what you have to do.
댓글 수: 16
Jacob
2019년 5월 3일
Steven Lord
2019년 5월 3일
As an example, 23 is 2*10 + 3.
How would you decompose 1234 in a similar way?
Jacob
2019년 5월 3일
Guillaume
2019년 5월 3일
Where does the 10 come from in the question
Your fingers! We've been using the decimal system for a while now...
You do not decompose 1234 into 10*123 + 4. Come on, you've been taught that in primary school or even earlier. Units, Decades, Hundreds, Thousands, etc.
Jacob
2019년 5월 3일
Rik
2019년 5월 3일
%So for two integers a and b
rem(a,b)
%returns a value c such that
a=m*b+c
%where m is an integer m, and c<b
How do you think this relates to the decomposition here?
Jacob
2019년 5월 4일
Rik
2019년 5월 4일
It is a step by step process:
- Given 1234, what is the last digit? That has the same answer as finding the remainder for 1234/10.
- Now we have a variable with the value 4, how can we convert 1234 to 123 to get it ready for the next step? Subtract the remainder and apply the division: (1234-4)/10.
- Now we have 123, what is the last digit? That has the same answer as .......
- ....
In the end you have a variable for each digit of your input number (in this case the ID).
Jacob
2019년 5월 4일
Walter Roberson
2019년 5월 4일
six = rem(YourID, 10);
rest = (ID - six)/10;
five = rem(rest, 10);
rest = (last - five)/10;
four = rem(rest, 10);
rest = (last - four)/10;
three = rem(rest, 10);
rest = (last - three)/10;
two = rem(rest, 10);
one = (last - two)/10;
Jacob
2019년 5월 4일
Rik
2019년 5월 4일
Read the documentation for anonymous functions.
Jacob
2019년 5월 4일
Walter Roberson
2019년 5월 4일
f = @(x) one*x.^2 + two*x + three;
fplot(f, [-5 5])
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!