Sunteți pe pagina 1din 4

17.

1 Project - Review of Fundamentals: (1/3) World's Longest Tunnels


Đáp án là
The longTunnels.txt file contains tunnels = readtable('longTunnels.txt');
information about tunnels in use around that
world that are at least 13 km long.
TASK Mình thì quên là phải dùng ‘’
Read longTunnels.txt into a table
named tunnelsin MATLAB.

The histogram function can bin on histogram(tunnels.Year,'BinMethod','integers')


integer values. Use
the BinMethod property name and
specify the value as 'integers'.

histogram(data,'BinMethod','integ
ers')
TASK
Create a histogram of the years, found in
the Yearvariable of tunnels, that the
tunnels were completed. Give each year in
the range its own bin.

Many different types of tunnels are tunnels.Type = categorical(tunnels.Type);


represented in the Type variable types = categories(tunnels.Type)
of tunnels. pa = tunnels(tunnels.Type == 'Particle Accelerator',:)
TASK
Convert Type to a categorical array.

Save the different types of tunnels to a cell


array named types.

Save a table named pa with all the data for


the Particle Accelerator type
in tunnels.

The Region variable in tunnels contains tunnels.Region = categorical(tunnels.Region);


the country or region in which the tunnel histogram(tunnels.Type(tunnels.Region=='Japan'))
can be found. title('Longest Tunnels in Japan')
TASK
Convert Region to a categorical array.

Make a histogram of the tunnel Type for


only those tunnels in Japan.

TASK tunnels.Continent =
There are five cell arrays mergecats(tunnels.Region,europe,'Europe');
named europe, na, sa, asia, tunnels.Continent =
and africa defined in the script. They mergecats(tunnels.Continent,na,'North America');
contain a list of countries in the dataset. tunnels.Continent =
Use these cell arrays to create a new mergecats(tunnels.Continent,sa,'South America');
categorical variable tunnels.Continent =
named Continent in tunnels. This
mergecats(tunnels.Continent,asia,'Asia');
variable should have the following
tunnels.Continent =
categories:
mergecats(tunnels.Continent,africa,'Africa');
 Europe histogram(tunnels.Continent(tunnels.Type == 'Railway'))
 North America title('Longest Railway Tunnels')
 South America
 Asia
 Africa

Create a histogram of the continents for


only the Railway tunnels.
17.1 Project - Review of Fundamentals: (2/3) Baseball Player Statistics
The file baseballPlayers.txt contains players = readtable('baseballPlayers.txt')
season statistics for several top offensive
baseball players throughout time.
TASK
Read baseballPlayers.txt into a table
named players in MATLAB.

The variable Pos in the players table TASK


contains each player's position. Convert Pos to a categorical.
 1B: First Base
Combine all the outfield positions (LF, CF, RF, and OF) into one
 2B: Second Base category, OF.
 3B: Third Base Then, create a histogram of the data in Pos.
 SS: Short Stop Mình làm mà bị sai
 C: Catcher players.Pos = categorical(players.Pos)
players.OF =
 LF: Left Field
mergecats(players.LF,players.CF,players.RF,players.OF)
 CF: Center Field histogram(players.Pos,'BinCounts','integer')
 RF: Right Field Còn đáp án là đơn giản hơn mình hiểu rất nhiều
 OF: Outfield (general) players.Pos =
mergecats(categorical(players.Pos),{'OF','LF','CF','RF'
 DH: Designated Hitter },'OF');
histogram(players.Pos)
Which position is most represented in the
data?

Runs created is a statistic used in baseball TASK


to estimate the number of team runs an Add two variables, TB and RC, to players. Use the formulas given. Make
individual contributed to. a scatter plot of RCversus Year.
lbEra = players.Year >= 1920;
lbPlayers = players(lbEra,:);
A = H + BB
scatter(lbPlayers.RBI,lbPlayers.RC)
B = TB
xlabel('Runs Batted In')
C = AB + BB
ylabel('Runs Created')
The variables H (hits), BB (base on balls),
and AB (at bat) are all in players.
title('Comparing Baseball Statistics')
TB (total bases) must be caculated from
other variables found in players.
TB = H + B2 + 2*B3 + 3*HR
The variables B2 (double, more commonly
abbreviated as “2B”), B3 (triple, more
commonly abbreviated as “3B”),
and HR (homerun) are all in players.

TASK c = polyfit(lbPlayers.RBI,lbPlayers.RC,1);
Add a straight fitted line to the plot. RBIfit = [min(lbPlayers.RBI) max(lbPlayers.RBI)];
RCfit = polyval(c,RBIfit);
hold on
plot(RBIfit,RCfit)
hold off

17.1 Project - Review of Fundamentals: (3/3) Cassini-Huygens Spacecraft


The file cassini.txt contains data on the TASK
location of the Cassini-Huygens spacecraft Read the data from cassiniData.txt into a table named cassini.
for the first several years of the probe's
mission. In this project, you'll visualize the Read the data from planetData.txt into a table named planets.
position of the spacecraft around the sun.
cassini = readtable('cassiniData.txt')
planets = readtable( 'planetData.txt')
TASK hold on
Plot the x-y position of the spacecraft, using for k = min(cassini.yr):max(cassini.yr)
variables x and y in the table cassini.
plot(cassini.x(cassini.yr==k),cassini.y(cassini.yr==k))
Use the yr variable to plot each year in a end
different color than the prior year. hold off

TASK th = linspace(0,2*pi)';
Add the orbits for the first six planets xc = cos(th);
in planets to the plot using black dotted yc = sin(th);
lines. hold on
for k = 1:6
For each planet, use the value in Radius to
create the x-y data needed to plot a circular plot(planets.Radius(k)*xc,planets.Radius(k)*yc,'k:')
orbit.
end
hold off
TASK r = round(sqrt(cassini.x.^2 + cassini.y.^2 +
Add a variable named Times to cassini.z.^2),2);
the planets table which contains the t = zeros(length(planets.Radius),1);
number of times the spacecraft intersects for k = 1:length(planets.Radius)
the orbit of each of the planets. t(k) = nnz(r == planets.Radius(k));
end
planets.Times = t

S-ar putea să vă placă și