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

附加练习结果:

相关推荐
北纬的小熊4 小时前
Matlab Simulink电力电子仿真-全桥 LLC 谐振变换器调频控制(PFM)仿真研究
嵌入式硬件·matlab
星夜离尘561 天前
MATLAB 清洗 CSV 采样日志:重复时间戳、无效行、分组统计与自动出图
开发语言·matlab·数据分析·数据清洗·csv
星夜离尘561 天前
MATLAB FFT 单边幅度谱:归一化、奇偶长度与频谱泄漏的完整实验
开发语言·matlab·信号处理·频谱分析·fft
星夜离尘561 天前
MATLAB 5 点滑动平均:filter 与 conv 的输出对齐,以及 2 样本延时的含义
开发语言·算法·matlab·滤波·fir
道道_Love2 天前
AI 调 MATLAB 用 MCP 太难用?单元设计规范和测试用例,用原生 AI 一次生成
人工智能·matlab·设计规范
菜鸟~noob2332 天前
【电子战】第31篇:3D AOA 定位——方位+俯仰联合
开发语言·matlab·3d
iCxhust3 天前
Matlab求解发电机的极限切除角
开发语言·算法·matlab·电力系统
LMT_Lanmantech3 天前
MATLAB合规管理:如何避免侵权赔偿和审计风险
开发语言·matlab·信息可视化
Evand J3 天前
【PMSM例程6】永磁同步电机(PMSM)基于增广EKF的d-q轴电感分阶段辨识算法|电机参数估计与误差分析
算法·matlab·电机·ekf
Matlab程序猿3 天前
【MATLAB源码-第460期】基于matlab的OTFS通信系统SLM峰均比抑制及非线性功率放大器失真与误码性能仿真
开发语言·算法·matlab·slm·otfs