MATLAB Fundamentals>>>(2/2) Project - Analyze Vehicle Data

#创作灵感#

MATLAB基础知识官方课程学习笔记


MATLAB Fundamentals>Common Data Analysis Techniques>Summary of Common Data Analysis Techniques>(2/2) Project - Analyze Vehicle Data


任务名称:Fuel Economy Analysis


任务1:

The variable mpg contains NaN values. Find the rows in mpg with NaN values, and remove those rows from all three data vectors: mpg, hp, and wt.

解答1:

Matlab 复制代码
nanIdx = ismissing(mpg)
mpg = mpg(~nanIdx);
hp = hp(~nanIdx);
wt = wt(~nanIdx);

结果1:


背景:

Fuel economy in the U.S. is typically given in miles/gallon. In many countries, however, the standard units are liters/100km.

Given mpg, you can calculate economy in L/100km by dividing 235.214583 by mpg.

任务2:

Create a variable econ that contains the fuel economy in L/100km rather than miles/gallon.

Combine the data for weight, horsepower, and fuel economy in L/100km (in that order) into a 48-by-3 matrix called numdata.

解答2:

Matlab 复制代码
econ = 235.214583./mpg
numdata = [wt hp econ]

笔记:注意mpg是个向量,需要使用"./"。

结果2:


任务3:

Create a matrix of the scatter plots of the variables in numdata (weight, horsepower, and fuel economy) in a single figure.

Calculate the corresponding correlation coefficients and store them as a matrix called cc.

解答3:

Matlab 复制代码
plotmatrix(numdata)
cc = corrcoef(numdata)

结果3:


任务4:

Determine the best-fit line (i.e., a first degree polynomial fit) for fuel economy (in L/100km) as a function of vehicle weight.

Evaluate the fitted model at the weights in the data. Store the fitted values in a vector called econFit.

Note that you do not need to use centering and scaling for the fit.

解答4:

Matlab 复制代码
c = polyfit(wt,econ,1)
econFit = polyval(c,wt)

结果4:


任务5:

Create a scatter plot of fuel economy against weight, and add the best-fit line as a red line.

解答5:

Matlab 复制代码
scatter(wt,econ)
hold on 
plot(wt,econFit,"r")
hold off

结果5:


附加练习:

Try fitting a line to horsepower as a function of weight. Try plotting both scatter plots and fits together, using yyaxis to accommodate the different scales:

附加练习解答:

Matlab 复制代码
chp = polyfit(wt,hp,1)
hpFit = polyval(chp,wt)
yyaxis right
hold on
scatter(wt,hp)
plot(wt,hpFit)
hold off

附加练习结果:

相关推荐
yong999012 小时前
IHAOAVOA:天鹰优化算法与非洲秃鹫优化算法的混合算法(Matlab实现)
开发语言·算法·matlab
沅_Yuan15 小时前
基于改进型PNGV的锂电池等效电路模型【MATLAB】
matlab·建模·锂电池·等效电路模型·pngv
沅_Yuan16 小时前
CALCE锂电池老化数据集处理与健康因子提取【MATLAB】
matlab·数据集·健康因子·calce·锂电池soh
神仙别闹17 小时前
基于 MATLAB 实现的流载体的LSB隐藏项目
开发语言·matlab
Matlab程序猿小助手20 小时前
【MATLAB源码-第315期】基于matlab的䲟鱼优化算法(ROA)无人机三维路径规划,输出做短路径图和适应度曲线.
开发语言·算法·matlab
gihigo199821 小时前
分布式发电的配电网有功-无功综合优化 MATLAB 实现
开发语言·分布式·matlab
guygg881 天前
NSGA-II自定义优化函数MATLAB实现
开发语言·matlab
沅_Yuan2 天前
基于LSTM神经网络的锂电池SOH估算模型(NASA数据集)【MATLAB】
神经网络·机器学习·matlab·锂电池·nasa·soh
沅_Yuan2 天前
基于KAN神经网络的锂电池SOH估算模型(NASA数据集)【MATLAB】
神经网络·机器学习·matlab·锂电池·nasa·soh
简简单单做算法2 天前
基于PSO粒子群优化的Transformer-BiLSTM网络模型的时间序列预测算法matlab性能仿真
matlab·transformer·时间序列预测·bilstm·pso粒子群优化