Question

Write a code such that for any given vector with integer components, it finds the elements...

Write a code such that for any given vector with integer components, it finds the elements which are the multiples of both 6 and 9.

in matlab

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem is solved using open source compiler Octave

########### MATLAB CODE #############

clc;
clear all;
A=input('Enter Array');
[m n]=size(A);
for i=1:n
if (mod(A(i),6)==0)
B(i)=A(i);
elseif(mod(A(i),9)==0)
B(i)=A(i);
end
end
B=B(B~=0);
fprintf('Elements that are multiple of 6 & 9 are =')
disp(B)

################ OUTPUT #################

e.g 1

Enter Array> [1 2 3 4 6 8 45]
Elements that are multiple of 6 & 9 are =    6   45
 
e.g 2
 
Enter Array> [199 81 56 72 4 5 90 100 35 34 ] Elements that are multiple of 6 & 9 are = 81 72 90
Add a comment
Know the answer?
Add Answer to:
Write a code such that for any given vector with integer components, it finds the elements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. I. Write a MATLAB code to find whether a given positive integer is a perfect...

    4. I. Write a MATLAB code to find whether a given positive integer is a perfect number or not. A perfect number is a positive integer that is equal to the sum of its proper divisors. II. Write a MATLAB code to find the number of digits of a given positive integer. III. Consider the vector ? = −10, −7, −4, … , 14. Replace all negative entries with zeros.

  • Write a MATLAB code that can convert a vector in any coordinate system to the other...

    Write a MATLAB code that can convert a vector in any coordinate system to the other two coordinate systems. The code must ask the use to select in which coordinate system is the entered data. Write a MATLAB code that can convert a vector in any coordinate system (Cartesian, cylindrical or spherical) to the other two coordinate systems. The code must ask the use to select in which coordinate system is the entered data.

  • Write a piece of code that finds the minimum integer (minValue) in an array (arInt) of...

    Write a piece of code that finds the minimum integer (minValue) in an array (arInt) of three cells. Notes: • Assume the array (arInt) is already defined and contains three integer values. • You must not use any repetitions in java language only

  • Assume that y is a column vector with ten elements, write matlab code that will create...

    Assume that y is a column vector with ten elements, write matlab code that will create a stem plot of the vector starting at a horizontal axis value of 1. Add code that will create the stem plot of the vector starting at a horizontal axis value of 0. Create additional code that creates a stem plot but plots y at every other horizontal value (i.e., 0, 2, 4, etc)

  • 1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N comp...

    1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N components; location 2 complete the Matlab function with header function [valuelagrangeforminterpolation(N,x,yz) so that it uses the Lagrange form to output the value of the Lagrange interpolating polynomial at Remember Lagrange form: 1. (25 pts) Given integer N>0; vector x of distinct nodes with N components; vector y of valucs at nodes with N components; location 2 complete the...

  • Write a program that passes an array of 100 elements (from 1 to 100) to a...

    Write a program that passes an array of 100 elements (from 1 to 100) to a function which is called MultipleOf7 as an input and this function should check if these elements are multiples of 7 or not. The output of the function should be an array that includes the elements that are multiples of 7. (MATLAB CODE)

  • 1. (25 pts) Given integer N > 0; vector r of distinct nodes with N components,...

    1. (25 pts) Given integer N > 0; vector r of distinct nodes with N components, ordered from smallest to largest; vector y of nonzero values at nodes with N components suppose the piecewise linear interpolant P(x) of this data has a root. Complete the Matlab function with header function [root] linearinterpolationroot(N,x.y) so that it outputs the smallest root of P(r). Remember, the piecewise linear interpolant is only defined between the smallest and largest nodes. 1. (25 pts) Given integer...

  • Write a function that receives a positive integer as input and returns as output a vector...

    Write a function that receives a positive integer as input and returns as output a vector containing all factors of the given integer. MATLAB

  • Write a program that reads an integer k from user and finds the number of elements...

    Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assignment4.txt. A number n is divisible by k if n = kx for some integer x > 0. You can use the mod operator % to test for divisibility. The file assign4.txt has integer values in the range [0,100 ]. You should use end-of-file controlled loop for this problem. Sample execution is given below. Assume the...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT