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
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
Jacob 2019년 5월 3일
Thanks. So I need to work with the one that shows the example
a = 1:5;
b = 3;
r = rem(a,b) ?
How do I apply this to my number?
Rik
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
Rena Berman 2019년 5월 13일
(Answers Dev) Restored edit

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

답변 (1개)

Guillaume
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
Jacob 2019년 5월 3일
Thanks but i'm still confused. Where does the 10 come from in the question?
Steven Lord
Steven Lord 2019년 5월 3일
As an example, 23 is 2*10 + 3.
How would you decompose 1234 in a similar way?
Jacob
Jacob 2019년 5월 3일
10*123 + 4. I don't understand how using rem gets what the question is asking for.
Guillaume
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
Jacob 2019년 5월 3일
1000 + 200 + 30 + 4. I just did what he had done with his example. I don't know how this relates to the rem function though?
Guillaume
Guillaume 2019년 5월 3일
As I asked, given 1234
  • what is the remainder of 1234 / 10
  • what is the remainder of 123 / 10
  • what is the remainder of 12 / 10
and what does the rem function do?
Have you read the documentation for what the rem function does? It calculates the remainder.
%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
Jacob 2019년 5월 4일
Yeah and I don't know. Do I have to find a way to get the remainder to be ID number?
Rik
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
Jacob 2019년 5월 4일
Thanks but I still don't know how to do this on Matlab. Do I start with an input thing for each of A, B, C etc. and then use the rem function?
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
Jacob 2019년 5월 4일
Thanks Walter.
How do I let f(x) equal A*x^2 + B*x + C and then sub in f(x1)? I keep getting "undefined function or variable 'x'."
Rik
Rik 2019년 5월 4일
Read the documentation for anonymous functions.
Jacob
Jacob 2019년 5월 4일
How do I restrict the range of a function on a plot?
Rik
Rik 2019년 5월 4일
Read the documentation for fplot.
f = @(x) one*x.^2 + two*x + three;
fplot(f, [-5 5])

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2019년 5월 3일

댓글:

2019년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by