MATLAB Write a function called vectornumber that takes an at

MATLAB: Write a function called vector_number that takes an at most two-dimensional matrix A as its sole input. The function returns a row vector v containing all elements of A that are prime numbers. The elements of v are stored according to row-major ordering of A. You are allowed to use the isprime built-in function

Solution

%%%% Main programm %%%%

clc;
clear all;
close all;

A=[ 3 8 37;2 4 1; 7 8 4]; %%% Defining input vector

v=vector_number(A)

%%%% Function body %%%%%

function v=vector_number(A)
B=isprime(A);
[a,b]=size(A);
k=0;
for i=1:a
for j=1:b
if (B(i,j)==1)
k=k+1;
v(k)=A(i,j);
end
end
end
if (k==0)
display(\'N0 prime number in given matrix\');
end

%%%% Output %%%%

v =

3 37 2 7

MATLAB: Write a function called vector_number that takes an at most two-dimensional matrix A as its sole input. The function returns a row vector v containing a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site