Question
Using matlab
Write a function that receives a vector as an input argument and prints the individual elements from the vector in a sentence format. One example of calling this function on the command window looks like >>printvec([1.12 23 9.245]) Element 1 is 1.12 Element 2 is 23.00 Element 3 is 9.25 1. (Note: your function should work for any vector.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1
function printvec(v)
    for i=1:length(v)
        fprintf("Element %d is %.2f\n",i,v(i));
    end
end

Note Please comment below if you have any doubts

Add a comment
Know the answer?
Add Answer to:
Using matlab Write a function that receives a vector as an input argument and prints the...
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
  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • Write a program that can find the smallest element in a vector. Given a vector such...

    Write a program that can find the smallest element in a vector. Given a vector such as [1 2 -2 7 -8 9 3 1], you program has to find its smallest element and output it in the command window. In the vector above, the smallest element would be the -8. Your program should work for any vector with any size. the answer should be answered by matlab.

  • Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr,...

    Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...

  • Problemi Consider the plecewise function sit) defined as follows: -(+2 when -2sts2 0.5 elsewhere s(t)- Write...

    Problemi Consider the plecewise function sit) defined as follows: -(+2 when -2sts2 0.5 elsewhere s(t)- Write a MATLAB user-defined function called aystfun.n that has one input argument to, and two output arguments: s0 and vsO. Your function must satisfy all the following requirements: 1. Your function must calculate and return the vector so - s(t0) for any supplied numerical vector to. We assume that the function is always called with a vector t0 whose elements are all in [-4,4]. 2....

  • What would the function look like in MATLAB? Write a function called mysort that takes a...

    What would the function look like in MATLAB? Write a function called mysort that takes a 3-element vector as its sole arguments. It uses if statements, possibly nested, to return a 3-element vector with its elements in non-decreasing order, i.e., the first element in the returned vector equals the smallest element of the input vector and the last element equals the largest element in the input vector. NOTE: Your function should not use any built-in functions, e.g., sort, min, max,...

  • MATLAB Homework 3- Due:5/20/2018 1. Create a function that receives the following input data, and prints...

    MATLAB Homework 3- Due:5/20/2018 1. Create a function that receives the following input data, and prints the output as the summation of the diagonal elements (The elements which are located at the intersection of similarly numbered rows and columns) Input (Matrix A) Output (Scalar B) Example 2 -1 4 3 -45 ? B = A( 1,1) + A(2,2) = 2-4 =-2 A4 5 ?41 ? B = A(1,1) + A(2,2)--1-4-5 -3 1 1.5 -4 3.2 -1 06 1.78 2.22 -4.56...

  • Create a new function file and write a function s= SUM_EVEn_ ubitname(V) that takes a vector...

    Create a new function file and write a function s= SUM_EVEn_ ubitname(V) that takes a vector V of arbitrary length and determines the sum of the even element and assign it to s. your function calculations must do the following: * Use a loop that iterates through every element of V and adds s only even element and skips all other elements. * Contain the appropriate H1 and help text lines. * Note: A number is even, if round(number/2) is...

  • Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following...

    Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following math function with x the input argument and y the output y(x)=0.8x4-13x2-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4pl.m to a) Use the function to calculate y(3) and y(5) and display the results in command window b) Use the function to make a plot of the function y(x) for -5:5: x 5:5. Label...

  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a...

    [MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...

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