Write a script.Create a vector of five random integers, each in the range from -10 to 10.Perform each of the following:•Subtract 3 from each element•Count how many are positive•Get the minimum

can someone please help me do this problem? i don't know

5 Commenti

What have you done so far? Please post your code and we can comment on it and offer suggestions. Do you know how to write a script? Do you know how to create a vector? Have you read the Getting Started section of the documentation?
>> vec= [-10:5:10]
vec =
-10 -5 0 5 10
>> min(vec)
ans =
-10
>> find(vec > 0)
ans =
4 5
>> vec - 3
ans =
-13 -8 -3 2 7
that's what i did but i don't know if that is right or not.
With the exception that the integers are NOT really very random. So how will you generate random integers? There are several tools that can help you here. What do you find when you look?
will it be like that vec=randi[-1:5:10] ? or vec=rand[-1:5:-10]

Accedi per commentare.

Risposte (1)

To create a script file, do the following at the command prompt:
edit my_script_name.m
The editor should open up a file for you. Enter your MATLAB code in this file, line by line, and terminate each line with a semi-colon ;
To run the script, simply enter its name at the command line:
my_script_name
To create vec, your code above does not do this randomly. To do it randomly, look at the following function:
doc randi
To count how many are positive, consider using the "sum" function instead of the "find" function. (You are not asked to find the positive element positions, just count how many of them there are)

Categorie

Scopri di più su MATLAB Coder in Centro assistenza e File Exchange

Richiesto:

il 9 Feb 2017

Commentato:

il 9 Feb 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by