Hi Guys,
Need your quick help regarding an assignment question. The question is as follows:
The function differ is defined like this:
function w = differ(v,a,b,c)
The first input argument v is a vector, while a, b, and c are all scalars. The function replaces every element of v that is equal to a with b and c. For example, the command
>> x = differ([1 2 3],2,4,5);
makes x equal to [1 4 5 3]. If c is omitted, it replaces occurrences of a with two copies of b. If b is also omitted, it replaces each a with two zeros.

댓글 수: 4

Geoff Hayes
Geoff Hayes 2015년 5월 17일
Jalashwa - please clarify what your question is. What have you tried so far, and what don't you understand with resepct to this assignment?
Jalashwa
Jalashwa 2015년 5월 17일
Geoff, i tried different scenarios as to how can i get to bottom of the question but to know avail. I have tried going by the flow of the question but have got nowhere close
Geoff Hayes
Geoff Hayes 2015년 5월 17일
Jalashwa - since you have tried out different scenarios, then you must have written some code. Please post it and the MATLAB community can respond with suggestions on how best to go about solving the problem.
Jan
Jan 2015년 5월 17일
@Jalashwa: Please post what you have tried so far and ask a specific question. The forum will not solve your homework.

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

답변 (2개)

Image Analyst
Image Analyst 2015년 5월 17일

0 개 추천

Here's some help : http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers Other than that I suggest you look up find() in the help, and look up isempty(), the "if statement", and logical comparisons like "==" if you need to review them. Also look up indexing so you'll know what expressions like v(1:n) and v(m:end) mean. After you've written some code, if you still need help with error messages then read this first and look at this and if you still have trouble, come back here.

댓글 수: 3

Another hint: many MATLABers would use strrep() for this - it's perhaps a little known trick that it works for integer arrays as well as strings.
Jalashwa
Jalashwa 2015년 5월 17일
Image Analyst, i am just a beginner and this Assignment is really important. I am trying again with the hint you have given me. May i request you to give me some more clarity please....
Here's a little bit more
function w = differ(v,a,b,c) % What your teacher gave you already.
w=strrep(v, a, [b,c]); % Trick I told you about
You can use nargin and vargin to handle situations where b and/or c are not present. Look those up in the help. I can't really help anymore without basically doing the whole thing for you.

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

Walter Roberson
Walter Roberson 2015년 5월 17일

0 개 추천

To detect whether an argument is present or not, look at exists()

카테고리

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

제품

질문:

2015년 5월 17일

댓글:

2015년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by