To write:
A
Answer to Problem 27E
Solution:
The file is,
%MATLAB code to load the data and create a data structure file.
%structure file.
stormdata = [321 2.4 1.5]
save stormdata.dat stormdata -ascii
stormdata = [111 3.3 12.1]
save stormdata.dat stormdata -ascii
clear
load stormdata.dat
%end of function file
%The function file should be placed in the same folder
The function file is,
%MATLAB code to print a table between stormdatavector and intensity.
%function file.
function tableprint(stormdatavector, intensity)
for i = 1:length(stormdatavector)
fprintf('%20.1f\t%20.1f\t%20.1f|t%20f\n', stormdatavector(i).locationcode, stormdatavector(i).rainfallamount, stormdatavector(i).stormduration, intensity(i))
end
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to calculate the average intensity.
%function file.
function avgintensity(intensity)
intensitysum = 0;
for i = 1:length(intensity)
intensitysum = intensitysum + intensity(i);
end
avgintensity = intensitysum/length(intensity);
fprintf('Average intensity of storm is %f\n', avgintensity)
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to find the information about mostintensestorm.
%function file.
function mostintensestorm(stormvector, intensity)
for i = 1:length(intensity)
for j = i + 1:length(intensity)
if intensity(i)>intensity(j)
temp = intensity(i);
intensity(i) = intensity (j);
intensity(j) = temp;
end
end
end
fprintf('the information of most intense storm is:%f\n', intensity(length(intensity)))
tempindex = index(stormvector, intensity);
fprintf('the index of most intense storm is:%d\n', tempindex);
fprintf('%20s|t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
fprintf('%20.1f\t%20.1f\t%20.1f\t%20f\n', stormvector(tempindex).locationcode, stormvector(tempindex).rainfallamount, stormvector(tempindex).stormduration, intensity(length(intensity)))
end
function index = index(stormvector, intensity)
for i = 1:length(stormvector)
if intensity(length(intensity)) ==stormvector(i).rainfallamount/stormvector(i).stormduration
index = i;
break;
end
end
end
%end of function file
%The function file should be placed in the same folder.
The function file is,
%MATLAB code to find the output.
%function file.
fprintf('%20s\t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
for i = 1:size(stormdata, 1)
for j = 1:length(stormdata(i))
stormvector(i) = struct('locationcode', stormdata(i, j),'rainfallamount', stormdata(i, j+1),'stormduration', stormdata(i, j+2));
intensity(i) = stormvector(i).rainfallamount/stormvector(i).stormduration;
end
end
tableprint(stormvector, intensity)
avgintensity(intensity)
mostintensestorm(stormvector, intensity)
%end of function file
%The function file should be placed in the same folder.
Explanation of Solution
The output is,
The average intensity is,
The location code is,
The rainfall amount is,
MATLAB Code:
clc
clear all
close all
%MATLAB code to load the data and create a data structure file.
%structure file.
stormdata = [321 2.4 1.5]
save stormdata.dat stormdata -ascii
stormdata = [111 3.3 12.1]
save stormdata.dat stormdata -ascii
clear
load stormdata.dat
%end of structure file
%The file should be placed in the same folder
output;
%The function file should be placed in the same folder
%MATLAB code to print a table between stormdatavector and intensity.
%function file.
function tableprint(stormdatavector, intensity)
for i = 1:length(stormdatavector)
fprintf('%20.1f\t%20.1f\t%20.1f|t%20f\n', stormdatavector(i).locationcode, stormdatavector(i).rainfallamount, stormdatavector(i).stormduration, intensity(i))
end
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to calculate the average intensity.
%function file.
function avgintensity(intensity)
intensitysum = 0;
for i = 1:length(intensity)
intensitysum = intensitysum + intensity(i);
end
avgintensity = intensitysum/length(intensity);
fprintf('Average intensity of storm is %f\n', avgintensity)
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to find the information about mostintensestorm.
%function file.
function mostintensestorm(stormvector, intensity)
for i = 1:length(intensity)
for j = i + 1:length(intensity)
if intensity(i)>intensity(j)
temp = intensity(i);
intensity(i) = intensity (j);
intensity(j) = temp;
end
end
end
fprintf('the information of most intense storm is:%f\n', intensity(length(intensity)))
tempindex = index(stormvector, intensity);
fprintf('the index of most intense storm is:%d\n', tempindex);
fprintf('%20s|t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
fprintf('%20.1f\t%20.1f\t%20.1f\t%20f\n', stormvector(tempindex).locationcode, stormvector(tempindex).rainfallamount, stormvector(tempindex).stormduration, intensity(length(intensity)))
end
function index = index(stormvector, intensity)
for i = 1:length(stormvector)
if intensity(length(intensity)) ==stormvector(i).rainfallamount/stormvector(i).stormduration
index = i;
break;
end
end
end
%end of function file
%The function file should be placed in the same folder.
%MATLAB code to find the output.
%function file.
fprintf('%20s\t%20s\t%20s\t%20s\n','location code','rainfall amount','storm duration','intensities')
for i = 1:size(stormdata, 1)
for j = 1:length(stormdata(i))
stormvector(i) = struct('locationcode', stormdata(i, j),'rainfallamount', stormdata(i, j+1),'stormduration', stormdata(i, j+2));
intensity(i) = stormvector(i).rainfallamount/stormvector(i).stormduration;
end
end
tableprint(stormvector, intensity)
avgintensity(intensity)
mostintensestorm(stormvector, intensity)
%end of function file
%The function file should be placed in the same folder.
Save the MATLAB script with name, chapter8_54793_8_27E.m and function files with names tableprint.m, avgintensity.m, mostintensestorm.m and output.m in the current folder. Execute the functions by typing the functions name at the command window to generate output.
Result:
The result is,
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 8 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Please helparrow_forwardIf there are about 5,000,000 red blood cells in every one cubic millimeter of Mrs. Garcia's blood and there are about 4, 600, 000 cubic millimeters of blood in her body. How many red blood cells does Mrs. Garcia has in her body? Write your final answer both in standard notation and scientific notation.Step 1: Write the given data found in the problem.Step 2: Determine what is asked from the problem. Step 3: Decide on the operation and the equation to be used. Step 4: Show your solution. Step 5: Write your final answer.arrow_forwarda flute instructor examined student progressarrow_forward
- tion 2 of 15 Last summer, the Smith family drove through seven different states and visited various popular landmarks. The prices of gasoline in dollars per gallon varied from state to state and are listed below. $2.34, $2.75, $2.48, $3.58, $2.87, $2.53, $3.31 Click to download the data in your preferred format. CrunchIt! CSV Excel JMP Mac Text Minitab PC Text R SPSS TI Calc Calculate the range of the price of gas. Give your solution to the nearest cent. range: dollars per gallon DELL & 4. 7 8.arrow_forwardThe U.S. Geological Survey monitors and reports on earthquakes, providing daily real-time, worldwide earthquake lists. Some of the information for four of the 105 earthquakes of magnitude 1.5 or greater that occurred on May 10, 2013, is shown in the following table. Magnitude is given on the Richter scale and NST stands for the number of stations that reported the activity on the same earthquake. Complete parts (a) through (e) below. Time Magnitude Depth (km) NST Region 00:03:16 1.7 75.9 29 Alaska 04:59:11 1.7 134.9 18 Alaska 08:27:04 2.8 64.0 21 Alaska 23:30:09 4.2 10.0 34 China a. Identify the type of data provided by the information in the first column of the table. Also identify the variable under consideration. Quantitative, Continuous, Qualitative, Quantitative, Discrete, region where the earthquake occurred depth of the earthquake in kilometers number of stations reporting the earthquake…arrow_forwardPlease refer to the picture attached.arrow_forward
- Create scatterplot using Excel with the following variables: gender: 0 = male, 1 = female. height: in inches. weight: in pounds. First we will create a scatterplot to examine how weight is related to height, ignoring gender. To do that in Excel: Sort the data by gender: Hold down the Control key (Command key on MacOS) and click the A key to select all of the data in the worksheet. Select the Home tab, then the Editing group Sort & Filter -> Custom Sort. In the pop-up window, make sure that My list has headers box is checked and then choose gender from the pull-down menu next to Sort by. Click OK. Now select all of the data in columns B and C, select the Insert tab and in the Charts group choose Scatter. Choose the first scatterplot option (Scatter with only Markers). Now we have a scatterplot, but the data is all on the right of the plot. To fix this: Right-click on the x-axis, and choose Format Axis from the pop-up menu. Make sure that Axis Options is selected on the left, and…arrow_forwardplease. help me answer this question. thank youarrow_forwardplease answer 8d, e, and f.arrow_forward
- On May 3, 1999, 59 tornadoes hit a certain state in the largest tornado outbreak ever recorded for that state. Sixteen of these were classified as strong (F2 or F3) or violent (F4 or F5). Answer parts a through c below. Length of Length of Length of Path (miles) Intensity Path (miles) Intensity Path (miles) Intensity F3 F3 F3 F2 F2 F3 F5 F2 F2 F3 45 5 9 4 37 6 13 0 I 8 6 15 40 1 20 45 NNIIN F2 F2 F4 F4 a. Make a box-and-whisker plot of the data for length of path. Choose the correct plot below. A. O B. O C. F2 F3 15 8 14 3 45arrow_forwardB. Present the following data in Tabular Form. Stat Mountain Bike Shop has sold 50 bicycles the month of January. Similarly, in the month of February 60 bicycles were sold. While in March the sales go down to 45 and 30 in May.arrow_forwardIf a golf course is open 3,600 hours a year and 360 days a year, how often would the golf course be open in total yearly?arrow_forward
- Elementary Geometry For College Students, 7eGeometryISBN:9781337614085Author:Alexander, Daniel C.; Koeberlein, Geralyn M.Publisher:Cengage,Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell