Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using matlab, 3 Examining a subarray Write a function vectorQuery(v,n,r) to determine whether the number r appears in the first n components of vector v.

using matlab,

image text in transcribed

3 Examining a subarray Write a function vectorQuery(v,n,r) to determine whether the number r appears in the first n components of vector v. The function returns 1 if r is in the first n components of v and 0 otherwise. Your function assumes that v is a vector of numbers, n is a positive integer, and r is a number. Use a loop to do the search. (Do not use find or vectorized code.) Make sure that the loop index doesn't go out of bounds" (if n is greater than the length of vector v 4 Creating arrays of unknown lengt Write a function sequence (m) that generates a sequence of random integer numbers between 1 and m, inclusive, stopping when a value is repeated for the first time. The function returns an array containing all the numbers generated (in the order in which they were generated) except for the last value that is a repeated occurrence. Example: If the generated sequence is 3195 72 5, the array to be returned should be 3 19572 Hints: 1) Use the function vectorQuery that you have developed already. 2) When you don't know how long a vector needs to be, you can build it one component at a time. Here is an example to store only the even integer values that a user enters: % Prompt user to enter positive numbers and store the even integers in a vector v 0; % vector length so far num- input ('Enter a positive number: '); while num>0 if rem(num,2)-0 v(k)- num; end num- input ('Enter a positive number (negative to stop): '); end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions