Generate a random vector of 100 numbers ranging from 1 to 200. Write a MATLAB code to find the numbers which are multiple of 2 and 3. Create separate vectors for multiple of 2 and 3.
Show older comments
Generate a random vector of 100 numbers ranging from 1 to 200. Write a MATLAB code to find the numbers which are multiple of 2 and 3. Create separate vectors for multiple of 2 and 3.
Can anyone code this?
I tried this one
clc;
clear all;
vecA = randperm(200,100)
%Separate vectors for multiples of 2 and 3
j=1;
k=1;
for i=1:100
if rem(vecA(i),2)==0
mul2(j)= vecA(i);
j=j+1;
end
if rem(vecA(i),3)==0
mul3(k)= vecA(i);
k=k+1;
end
end
disp('multiple of 2')
disp(mul2)
disp('multiple of 3')
disp(mul3)
7 Comments
Walter Roberson
on 6 Nov 2020
Can anyone code this?
From a legal perspective, some people have been banned by judges from programming because of crimes they committed or are alledged to have comitted.
From a legal perspective, Mathworks terminated license rights of some people who abused the license, so those people would not be able to lawfully use MATLAB to code it.
From a human perspective, there are unfortunately people who are too ill to code it, such as people with profound Alzheimer's disease.
But other than those classes of people, anyone else should be able to code it if they do a some studying.
Sheikh Abuzar Amjad
on 6 Nov 2020
James Tursa
on 6 Nov 2020
What have you done so far? What specific problems are you having with your code?
Steven Lord
on 6 Nov 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
madhan ravi
on 6 Nov 2020
Show us what you have tried so far.
Sheikh Abuzar Amjad
on 7 Nov 2020
Walter Roberson
on 7 Nov 2020
No, the question does not require that the values are unique.
Answers (0)
Categories
Find more on Programming 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!