Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask MATLAB Expert

Objectives

The objectives are to introduce the following concepts:

• vector element access

• compound conditional statements

• pie charts

Deliverables

Submit your pre-lab answers in Bb Learn under the Lab 6 pre-lab assignment area prior to the start of class

1. We can access certain elements of a vector by specifying the index of the value we want in parentheses after the vector's name. Suppose we have a vector x = [1 5 3 6 3]. We would type x(2) to get the second value in the x vector or x(4) to get the fourth value in the x vector. If we want to multiply the fifth value in the x vector by 3, we would write x(5) = x(5) * 3.

Write the MATLAB code to add 1 to the third element of the x vector.

2. We can check for more than one condition in an if statement or while loop with the use of logical operators. The logical AND (&&) operator connects two Boolean values. If both of the Boolean values are true, then the expression returns true. Otherwise, the expression returns false. The logical OR (||) operator also connects two Boolean values. If either of the Boolean values are true, then the expression returns true. Otherwise, the expression returns false. Note that compound conditional operators can be chained together to make complex expressions.

i) The following would execute the code inside the while loop as long as a is greater than 7 or b is greater than 9. The code inside of the while loop adjusts the values of a andb so that there is not an infinite loop.

a = 14;
b = 12;
whilea>7 || b>9
a = a - 2;
b = b - 1;
end

Suppose we have a variable calledc, which represents some integer. Write the MATLAB code for a while loop that executes as long as c is greater than 4 or c is less than 11. Just show the while loop line. You do not need to include any code inside of the while loop.

ii) The following code would execute the code inside the while loop as long as d equals the character ‘u' and e equals the character ‘v'. The code inside the while loop asks the user for input to update the values of d and e.

d = input(‘Enter a value for d', ‘s');
e = input(‘Enter a value for e', ‘s');
while d == ‘u' &&e == ‘v'
d = input(‘Enter a value for d', ‘s');
e = input(‘Enter a value for e', ‘s');
end

Suppose we have a variable called f, which represents a character. Write the MATLAB code for a while loop that executes as long as f does not equal ‘u' and f does not equal ‘v'. Recall that MATLAB uses ~= to check if two values are not equal. Just show the while loop line. You do not need to include any code inside of the while loop.

3.The following links provide information on the pie, legend, and title commands.

http://www.mathworks.com/help/matlab/ref/pie.html
http://www.mathworks.com/help/matlab/ref/legend.html
http://www.mathworks.com/help/matlab/ref/title.html

Write the MATLAB code to set up the vector y = [2 4 3 6 2] and plot y in a pie chart. Add a legend and title to the pie chart. The legend should contain the following strings: ‘value1', value2', ‘value3', ‘value4', and ‘value5'. The title should be ‘My Awesome Pie Chart'.

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M91425934
  • Price:- $55

Priced at Now at $55, Verified Solution

Have any Question?


Related Questions in MATLAB

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignmentq1 find the laplace transforms of the following

Assignment Q.1 Find the Laplace transforms of the following functions: (a) t 2 + at + b and (b) sin(2nΠt/T) Q.2 Find f (t) for the following F(s) = α[ f (t)]. (i) 5/(s + 3), (ii) 1/s 2 + 25, (iii) 1/s(s+1) Q.3 Find the L ...

Lab assignment - matlab matrix relationallogical operators

Lab Assignment - MATLAB Matrix, Relational/Logical Operators and Plotting This laboratory exercise/assignment will involve you 1) practicing multiplication operators in MATLAB; 2) practicing relational and logical operat ...

Assignment matlab programmingusing appropriate matlab

Assignment: MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignment -we have daily gridded rainfall data of 40 years

Assignment - We have daily gridded rainfall data of 40 years and structure of the dataset is like below; Lat = [6.5:0.25:38.5]; Lon = [66.5:0.25:100]; Rainfall (135x129x365x40) (Lon, Lat, days, years). Now, we looking fo ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

Prepare a 3 - 10 pages long reportprepare a presentation

Prepare a 3 - 10 pages long report Prepare a presentation with 5 - 9 slides. The slides will include introduction (need and similar work), theoretical background (tested neural networks), Data, Results (Comparison of the ...

What comparison of means test was used to answer the

What comparison of means test was used to answer the question

Recitation problems -1 determine the highest real root of

Recitation Problems - 1. Determine the highest real root of f(x) = 2x 3 - 11.7x 2 + 17.7x - 5 using the Newton-Raphson method with at least four iterations. Start with an initial guess of x 0 = 3. 2. Determine the real r ...

Assignment -matlab codes and simulated model in

Assignment - Matlab codes and simulated model in simulink/matlab and truetime. 1. Matlab codes and simulink model for pid controller optimization using particle swarm optimization (PSO) my plant is integer order 1000/(s^ ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As