Question
can anyone help with a MatLab code?
Problem create a function that takes in the following vector DATA and returns the number of elements, the mean and the sum of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following syntax will be used in the desired coding.

  1. DATA= input('Enter the sequence'); It will ask you to enter a number. You have to enter the desired no DATA as required. Or u candirectly enter the value as DATA=  [2 4 5 6 7 8] in the editor itself.
  2. n= numel(DATA); it Return the number of elements of DATA . In this case it returns 6.
  3. S= sum(DATA); it Return the sum of the DATA . in this case it returns- 2+4+5+6+7+8= 32
  4. M= mean(DATA); it Return the mean of the DATA. in this case it returns , sum/ 6 . i.e 32divided by 6 = 5.33.

The complete Matlab function:

% Enter the DATA
DATA= input('Enter the sequence');

% Return the number of elements of DATA
n= numel(DATA);

% Return the mean of the DATA
M= mean(DATA);

% Return the sum of the DATA
S= sum(DATA);

Attaching the screen- shot also

Function is written on the Editor.

DATA value is entering through Command Window.

Values of no of elements (n), sum(S) and mean (M) returning in Workplace  

Add a comment
Know the answer?
Add Answer to:
can anyone help with a MatLab code? Problem create a function that takes in the following...
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
  • 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...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • Hello, can anyone help me solve this using MATLAB? Will rate well, thank you. You are...

    Hello, can anyone help me solve this using MATLAB? Will rate well, thank you. You are playing a game where you roll a fair dice 7 times. We set the sum of maximum value and minimum value as S. If S is 2, 5, or 12, you win 3 times S dollars; that is respectively 6,15, or 36. If S is 7 or 11, you win 2 times S dollars; that is respectively 14 or 22. If S is anything...

  • Need help with this MATLAB question 4.4 (25 points) Write and test the code for the...

    Need help with this MATLAB question 4.4 (25 points) Write and test the code for the function mysteryFunction that takes a vector, V, generate a new vector W, in which each element is the sum of the corresponding element in V and the previous element of V, and return two values (mysteryMean, mysteryStdev] of W. Consider the previous element of V(1) to be 0. For example, [mysteryMean, mysteryStdev] = mysteryFunction(1:8), W= [1 3 5 7 9 11 13 15] mysteryFunction...

  • can anyone help me solve these on MATLAB?? please intro to programming and computation 3. 50...

    can anyone help me solve these on MATLAB?? please intro to programming and computation 3. 50 points - The purpose of this question is to test your ability to write for loops, so you won't get points if your answer works without using for loop. A vector is given by V - (5. 17. -3,8,0,-7. 12, 15, 20. -6, 6, 4.-7.16). Write a program as a script file that doubles the elements that are positive and raise to the power...

  • MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when c...

    MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when called, it gives control to the user and asks the user to input a length-3 vector. Then the function prints: The sum of ___, ____, and ____ is ____. [new line] where the first three blanks are filled by each element in input vector, and the last blank is the sum of all three elements.

  • Create a function in JavaScript called "sum" that takes in an array as a parameter and...

    Create a function in JavaScript called "sum" that takes in an array as a parameter and returns the sum of all of the EVEN numbers in a given array. Please note: the array passed in can have any data type, i.e. Strings, Numbers, Booleans, undefined, etc. HINT: the expression typeof will help discern var types. For example if I have: var x = 4, and I do typeof(x) - the output would be "Number" Example run: sum([1, 4, 8, 10,...

  • In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename...

    In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename myrowproduct (A,x) Undefined function or variable 'Filename' Did you mean: mfilename : myrowproduct (A, x) Undefined function or variable 'myrowproduct' function y = myrowproduct(A,x); function y my rowp roduct (A, x); Error: Function definition not supported in this context. Create functions in code file. (, 2,,)T 4. The product y Ax of an m x n matrix A times a vector x= can...

  • This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no input...

    This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice This problem investigates how...

  • 1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should...

    1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should be in the same order: xmin xmax ymin ymax N: n is the number of elements in the vector x and y The ouputs should be in the same order: f_xy: is the calculated array f(x,y) f_xyMAX: should be the the maximum value of the function f(x,y). Hint: to create vectors x and y look up the matlab built-in function linspace() Hint 2: To...

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