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: mpghp, and wt.

解答1:

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:

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:

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:

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:

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:
 

附加练习解答:

chp = polyfit(wt,hp,1)
hpFit = polyval(chp,wt)
yyaxis right
hold on
scatter(wt,hp)
plot(wt,hpFit)
hold off

附加练习结果:

相关推荐

  1. -CMPEN431-SP24-Project-1

    2024-02-04 07:56:01       31 阅读
  2. npm ERR! vue@“^3.2.25“ from the root project

    2024-02-04 07:56:01       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-04 07:56:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-04 07:56:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-04 07:56:01       87 阅读
  4. Python语言-面向对象

    2024-02-04 07:56:01       96 阅读

热门阅读

  1. centOS linux 宝塔 部署django 遇坑小记

    2024-02-04 07:56:01       47 阅读
  2. 突破编程_C++_基础教程(指针(一))

    2024-02-04 07:56:01       39 阅读
  3. Vue中间件的讲解案例分析

    2024-02-04 07:56:01       44 阅读
  4. IP风险画像在企业网络统计与安全防范中应用

    2024-02-04 07:56:01       57 阅读
  5. mysql Change buffer详解

    2024-02-04 07:56:01       50 阅读
  6. volatile的作用

    2024-02-04 07:56:01       57 阅读
  7. LeetCode--455.分发饼干

    2024-02-04 07:56:01       57 阅读
  8. 区间DP,LeetCode 1690. 石子游戏 VII

    2024-02-04 07:56:01       47 阅读
  9. LeetCode每日一题 | 1690. 石子游戏 VII

    2024-02-04 07:56:01       48 阅读
  10. EmoLLM-心理健康大模型

    2024-02-04 07:56:01       46 阅读