How would I write a script to solve this problem. Assume that I have a vector named D. Using iteration (for) and conditionals (if and/or switch), separate vector D into four vectors posEven, negEven, posOdd, and negOdd.
Show older comments
*Find the maximum, minimum elements and get the summation and so on, but how would I solve the problem using conditional statement and iterations instead.***
a. posEven contains all of the positive even numbers in D b. negEven contains all of the negative even numbers in D c. posOdd contains all of the positive odd numbers in D d. negOdd contains all of the negative odd numbers in D
3 Comments
OCDER
on 28 Sep 2018
No one is going to do your homework because we all want you to learn the material. You could ask us for hints IF you show that you've at least tried but are having issues with a particular problem. Show us some code and ask "I got this code...
function Out = myCode(...)
, but how do I only get all the positive even numbers? I have heard about logical indexing, but I get all positives, and not even ones...."
Bryce Imbriale
on 28 Sep 2018
Edited: Walter Roberson
on 28 Sep 2018
Walter Roberson
on 28 Sep 2018
What difficulty are you observing?
Answers (1)
My guess is Bryce needs to "find the maximum and minimum elements, and get the summation" for each variable. But seems max, min, or sum cannot be used.
Start with:
maxPosEven = posEven(1);
for j = 2:numel(posEven)
if posEven(j) > maxPosEven %Adjust the inner contents for your case
maxPosEven = posEven(j);
end
end
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!