MATLAB 排序、拟合
一、数据排序整合
1、随机生成的数,从小到大排序
clear
rand('seed',1)%设置随机种子,确保随机数一样
edge_range=unifrnd (1, 10, 1, 10)
edge_height=unifrnd (1, 10, 1, 10)
subplot(311),plot(edge_range,edge_height)
title('初始值') temp(:,1) = edge_range.';%对应起来
temp(:,2) = edge_height.'; temp = sortrows(temp);%按列排序
edge_range1 = temp(:,1).'
edge_height2 = temp(:,2).'
subplot(312),plot(edge_range1,edge_height2)
title('y轴排序后值') temp = sortrows(temp,2);%按第二列列排序
edge_range1 = temp(:,1).'
edge_height2 = temp(:,2).'
subplot(313),plot(edge_range1,edge_height2)
title('x轴排序后值')

2、
clear
rand('seed',1)%设置随机种子,确保随机数一样
edge_range=unifrnd (1, 10, 1, 10)
edge_height=unifrnd (1, 10, 1, 10)
subplot(311),plot(edge_range,edge_height)
title('初始值') temp(:,1) = edge_range.';%对应起来
temp(:,2) = edge_height.'; ind = find(edge_range<6);%限制范围
ind2 = find(edge_height<6);%(m)
ind = intersect(ind,ind2);% 两个向量求交集
% ind = unique(sort(ind));%排序
temp = temp(ind,:);%???? temp = sortrows(temp);%按列排序
edge_range1 = temp(:,1).'
edge_height2 = temp(:,2).'
subplot(312),plot(edge_range1,edge_height2)
title('y轴排序后值') temp = sortrows(temp,2);%按列排序
edge_range1 = temp(:,1).'
edge_height2 = temp(:,2).'
subplot(313),plot(edge_range1,edge_height2)
title('x轴排序后值')

二、数据拟合
1、
clear all
load census;
subplot(211),
stem(cdate,pop)
f=fit(cdate,pop,'poly2');
subplot(212)
plot(f,cdate,pop)

2、
clear all
aa = sin(0:0.05:pi);%正弦函数
aa = aa+randn(1,63)/10;%添加噪声
bb = 0:0.05:pi;
subplot(211),plot(bb,aa,'bo');%图像
ff = fit(bb',aa','poly2');%2阶拟合
subplot(212),plot(ff,bb,aa);%拟合图像

拟合公式

计算偏移值和方差
figure
cc=-0.396*bb.^2+1.277*bb+-0.07073;%拟合方程
dd=cc-aa;%偏移值
plot(bb,dd)
s=std(dd);%标准差
ff=sqrt(sum((dd-mean(dd)).^2/(length(dd)-1)));%偏移值的标准差
ee=(cc-aa).^2/(length(cc)-1);
ee=sqrt(sum(ee));


可以看到ff和s相等,而ee与之不相等。
figure
x=0:0.05:2*pi;%扩充坐标轴
y=ff(x);
plot(x,y)
hold on
plot(bb,aa,'bo')

MATLAB 排序、拟合的更多相关文章
- MATLAB中拟合算法刚入门
%%%1.拟合问题:(做预测,主要使用的范围是样本比较小,拟合效果会好,样本比较多,拟合的效果就不是很好) 1.应用预测的场景:已经知道10年的样本,预测第11年以内的数据 2.用拟合的到关系式:样本 ...
- matlab切比雪夫拟合
matlab中没有切比雪夫拟合的现成算法,这里把我程序中的这部分抽出来,说一下. 1.首先是切比雪夫计算式 function [ res ] = ChebyShev(num,i) res=; else ...
- [matlab] 1.拟合
x = [1 2 3 4 5 6 7 8 9 ]; y = [9 7 6 3 -1 2 5 7 20]; p=polyfit(x,y,3); %数字代表拟合函数的阶数 xi=0:0.01:10; yi ...
- matlab函数拟合
1 函数拟合 函数拟合在工程(如采样校正)和数据分析(如隶属函数确定)中都是非常有用的工具.我这里将函数拟合分为三类:分别是多项式拟合,已知函数类型的拟合和未知函数类型的拟合.matlab中关于函数的 ...
- Matlab各种拟合
作者:Z-HE链接:https://zhuanlan.zhihu.com/p/36103034来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1) polyfit 代码 ...
- matlab的拟合函数polyfit()函数
matlab的多项式拟合: polyfit()函数 功能:在最小二乘法意义之上,求解Y关于X的最佳的N次多项式函数. clc;clear; close all; x=[ ]; y=[2.7 7.4 2 ...
- Matlab 多项式拟合、稳健滤波等实用函数
Function summary http://www.biomecardio.com/matlab/index.html clinspace Curvilinearly spaced points ...
- Matlab多项式拟合測试
x=0:0.2:4; %生成等差数列 rnd=rand(1,size(x,2))*5; %生成一组随机数 y=x.*x.*x+x.*x+6+rnd; %生成y=x^3+x^2+6函数在垂直方向5个尺度 ...
- 【转】Matlab多项式拟合
转:https://blog.csdn.net/hwecc/article/details/80308397 例: x = [0.33, 1.12, 1.41, 1.71, 2.19] y = [0. ...
随机推荐
- 【Spring Data 系列学习】Spring Data JPA 自定义查询,分页,排序,条件查询
Spring Boot Jpa 默认提供 CURD 的方法等方法,在日常中往往时无法满足我们业务的要求,本章节通过自定义简单查询案例进行讲解. 快速上手 项目中的pom.xml.application ...
- hibernate中cascade属性以及inverse属性
级联操作 cascadecascade的常用属性值 none 默认值 不做任何变动 save-update 保存或修改 delete 删除 all 包含save-update 和delete等行为 c ...
- Flutter的盒子约束
由Expanded widget引发的思考 设计稿如下 布局widget分解 很常见的一种布局方式:Column的子widget中包含ListView @override Widget build(B ...
- SpringBoot入门系列(五)Thymeleaf的常用标签和用法
前面介绍了Spring Boot 中的整合Thymeleaf .不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/category/16577 ...
- Python自定义模块
自定义模块 自定义模块(也就是私人订制),我们要自定义模块,首先就要知道什么是模块 一个函数封装一个功能,比如现在有一个软件,不可能将所有程序都写入一个文件,所以咱们应该分文件,组织结构要好,代码不冗 ...
- vue中moment.js的使用
一.介绍 moment.js是一款现在对时间处理的强大的函数. Moment被设计用于在浏览器和Node.js中工作. 目前ci系统使用的浏览器有:IE8.IE9在Windows 7上.Chrome在 ...
- 「CSS」常见的清除浮动方法
下面介绍几种清除浮动的方案,供大家参考: 使用额外的标签clear:both .parent {padding: 10px;width: 200px;background: red;} .child ...
- 【Weiss】【第03章】练习3.21:单数组模拟双栈
[练习3.21] 编写仅用一个数组而实现两个栈的例程.除非数组的每一个单元都被使用,否则栈例程不能有溢出声明. Answer: 很简单,一个栈从数组头起,一个栈从数组尾起,分别保留左右栈头索引. 如l ...
- Journal of Proteome Research | An automated ‘cells-to-peptides’ sample preparation workflow for high-throughput, quantitative proteomic assays of microbes (解读人:陈浩)
文献名:An automated ‘cells-to-peptides’ sample preparation workflow for high-throughput, quantitative p ...
- springcloud基础-eureka(注册中心)案例
一.新建项目,取名eureka-server pom.xml <?xml version="1.0" encoding="UTF-8"?> < ...