一、数据排序整合

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 排序、拟合的更多相关文章

  1. MATLAB中拟合算法刚入门

    %%%1.拟合问题:(做预测,主要使用的范围是样本比较小,拟合效果会好,样本比较多,拟合的效果就不是很好) 1.应用预测的场景:已经知道10年的样本,预测第11年以内的数据 2.用拟合的到关系式:样本 ...

  2. matlab切比雪夫拟合

    matlab中没有切比雪夫拟合的现成算法,这里把我程序中的这部分抽出来,说一下. 1.首先是切比雪夫计算式 function [ res ] = ChebyShev(num,i) res=; else ...

  3. [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 ...

  4. matlab函数拟合

    1 函数拟合 函数拟合在工程(如采样校正)和数据分析(如隶属函数确定)中都是非常有用的工具.我这里将函数拟合分为三类:分别是多项式拟合,已知函数类型的拟合和未知函数类型的拟合.matlab中关于函数的 ...

  5. Matlab各种拟合

    作者:Z-HE链接:https://zhuanlan.zhihu.com/p/36103034来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1) polyfit 代码 ...

  6. matlab的拟合函数polyfit()函数

    matlab的多项式拟合: polyfit()函数 功能:在最小二乘法意义之上,求解Y关于X的最佳的N次多项式函数. clc;clear; close all; x=[ ]; y=[2.7 7.4 2 ...

  7. Matlab 多项式拟合、稳健滤波等实用函数

    Function summary http://www.biomecardio.com/matlab/index.html clinspace Curvilinearly spaced points ...

  8. 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个尺度 ...

  9. 【转】Matlab多项式拟合

    转:https://blog.csdn.net/hwecc/article/details/80308397 例: x = [0.33, 1.12, 1.41, 1.71, 2.19] y = [0. ...

随机推荐

  1. nginx如何连接多个服务?

    记录一下: 刚开始用nginx部署,在项目文件内touch了一个nginx.conf配置文件,然后将这个conf文件软链接到nginx的工作目录中 sudo ln -s /home/ubuntu/xx ...

  2. Python基础-求两个字符串最长公共前轴

    最长公共前缀,输入两个字符串,如果存在公共前缀,求出最长的前缀,如果没有输出no.如“distance”和“discuss”的最长公共前缀是“dis”. s1 = input('请输入第1个字符串-- ...

  3. 转pdf

    一.转印厂pdf(书本类及折页类) 1.储存为(Ctrl+Shift+S) 2.保存类型选择   pdf 3.常规==>Adobe PDF预设==>选择印刷质量 4.选择标记和出血==&g ...

  4. json中存整形数值,前端返回为空

    实现目标: 在servlet中将整型数值转为json,然后在前端获取 问题描述: 前端获取为空,显示为:console.log打印为:{} 解决办法: 在servlet中将数值转为json格式再进行传 ...

  5. [pdo_mysql.lo] Error 1 或者 [php_mysql.lo] Error 1

    make: *** [pdo_mysql.lo] Error 1 make: *** [php_mysql.lo] Error 1 这是因为这是因为在编译时需要 MySQL 的头的文件.而它按默认搜索 ...

  6. Ubuntu16.04 desktop 设置共享文件夹 -- 图形界面配置

    1. 安装 安装samba 直接采用 Ubuntu16.04 desktop 里面的安装向导来完成: 选中需要共享的文件夹 -> 右键 “local Network Share” -> 安 ...

  7. 第16个算法 - leetcode-二叉树的层次遍历

    二叉树的层次遍历 参考:https://www.cnblogs.com/patatoforsyj/p/9496127.html 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有 ...

  8. debug.js在手机上打印调试信息

    在做移动端开发的时候大家应该都遇到过这么一个问题:如何在手机上打印调试信息? 在pc端我们通常会用console.log 或者 alert,但大家知道console.log在手机上是看不到打印信息的: ...

  9. JavaSE知识概述集

    一.HelloWord(文档启动Java) /* 使用命令行的方式执行的时候,cmd的默认编码格式是GBK 因此在输入中文的时候需要设置文件的编码格式位ANSI,不会出现乱码错误 注意: 0.先用ja ...

  10. EPX-Studio操作多线程的方法

    procedure TF1167908962.Button1Click(Sender: TObject); begin ThIndex := ; EPXThread1.StartThread; EPX ...