matlab图像学习笔记

pcolor

伪彩图

全页折叠

语法

pcolor(C)

pcolor(X,Y,C)

pcolor(ax,___)

s = pcolor(___)

说明

示例

pcolor(C) 使用矩阵 C 中的值创建一个伪彩图。伪彩图以彩色单元(称为)阵列形式显示矩阵数据。MATLAB® 在 x-y 平面上创建该图的单一着色平面图。该平面由对应于各面的角(即顶点)的 x 坐标和 y 坐标的网格定义。网格覆盖区域 X=1:n 和 Y=1:m,其中 [m,n] = size(C)。矩阵 C 指定顶点处的颜色。每个面的颜色取决于其四个周围顶点之一的颜色。在这四个顶点中,x-y 网格中出现的第一个顶点决定该面的颜色。

示例

pcolor(X,Y,C) 指定顶点的 x 坐标和 y 坐标。C 的大小必须与 x-y 坐标网格的大小匹配。例如,如果 X 和 Y 定义一个 m×n 网格,则 C 必须为 m×n 矩阵。

示例

pcolor(ax,___) 指定绘图的目标坐标区。指定 ax 作为上述任何语法中的第一个参数。

示例

s = pcolor(___) 返回 Surface 对象。创建绘图后,使用 s 设置绘图属性。有关属性列表,请参阅 

matlab案例:

clc;
clear;
fname='mlotst_Omon_CESM2-WACCM_historical_r2i1p1f1_gr_185001-201412.nc';
ncdisp(fname);
%ocean data regridded from native gx1v7 displaced pole grid (384x320
%latxlon) 如果把极点放在真正南北极点模型会产生很大的误差
lat=ncread(fname,'lat');%lat=ncread(fname,'lat',[1,1,1],[Inf,Inf,12]) 可以取出第一年的Data  [long,lat,month]
lon=ncread(fname,'lon');
time=ncread(fname,'time');
MLD=ncread(fname,'mlotst');
MLD1=MLD(:,:,1);
figure(1);

pcolor(MLD1);
colorbar;
shading flat;%pcolor: pixel color
%shading faceted:默认模式,在曲面或图形对象上叠加黑色的网格线;
% shading flat:是在shading faceted的基础上去掉图上的网格线;
% shading interp:对曲面或图形对象的颜色着色进行色彩的插值处理,使色彩平滑过渡 ;

caxis([0 400]);

MLDp=permute(MLD1,[2,1,3]);%permute 指的是把矩阵中不同维度的数据进行交换 这里是交换1,2维度
figure(2);
pcolor(MLDp);colorbar;shading flat;
caxis([0 400]);% 把colorbar的一部分归0

MLD=permute(MLD,[2,1,3]);
[x,y,z]=size(MLD);
figure(3);
vidfile=VideoWriter('MLD_movie.mp4','MPEG-4');
open(vidfile);
for ji=1:20
    iMLD=MLD(:,:,ji);
    pcolor(iMLD);colorbar;shading flat;
    caxis([0 400]);%否则colorbar的数值会上下横跳
    drawnow;
    pause(0.1);%去掉括号里的数字可以手动切图(用回车)
    F(ji)=getframe(gcf);
    writeVideo(vidfile,F(ji));
end
close(vidfile);
save MLD1850 MLD lat lon;% MLD1850是文件名
%load时同理

箱式图

boxplot

用箱线图可视化汇总统计量

全页折叠

语法

boxplot(x)

boxplot(x,g)

boxplot(ax,___)

boxplot(___,Name,Value)

说明

示例

boxplot(x) 创建 x 中数据的箱线图。如果 x 是向量,boxplot 绘制一个箱子。如果 x 是矩阵,boxplot 为 x 的每列绘制一个箱子。

在每个箱子上,中心标记表示中位数,箱子的底边和顶边分别表示第 25 个和 75 个百分位数。须线会延伸到不是离群值的最远端数据点,离群值会以 '+' 符号单独绘制。

示例

boxplot(x,g) 使用 g 中包含的一个或多个分组变量创建箱线图。boxplot 为具有相同的一个或多个 g 值的各组 x 值创建一个单独的箱子

boxplot(ax,___) 使用坐标区图形对象 ax 指定的坐标区和任何上述语法创建箱线图。

示例

boxplot(___,Name,Value) 使用由一个或多个 Name,Value 对组参数指定的附加选项创建箱线图。例如,您可以指定箱子样式或顺序。

clear all; close all; clc
% A = rand(500,1);
A = normrnd(5,1,100,1);
B = normrnd(5,1,100,1);
Y = quantile(A,[0.25,0.5,0.75]);

w = 1.0 ; 
% boxplot([A,B], 'Whisker',w)
boxplot(A, 'Whisker',w)
q1 = Y(1);
q2 = Y(2);
q3 = Y(3);

text(1.1,q1,'25% percentile')
text(1.1,q2,'median')
text(1.1,q3,'75% percentile')

uwhickler = q3 + w * (q3 - q1);
dwhickler = q1 - w * (q3 - q1);
text(1.1, uwhickler, 'q3 + w * (q3 - q1)')
text(1.1, dwhickler, 'q1 - w * (q3 - q1)')

drawArrow = @(x,y) quiver( x(1),y(1),x(2)-x(1),y(2)-y(1),0 );

 分组进行箱式图的绘制

load MLD1850.mat MLD lat lon
[Lat,Lon] = meshgrid(lat,lon) ;
MLD=MLD(:,:,1);
ibig = find(MLD(:) >250);
MLD(ibig) = nan;
data = [Lat(:), MLD(:)] ;
ikp = find(~isnan(sum(data,2)) & ~isinf(sum(data,2)));

lat_kp = Lat(ikp);
mld_kp = MLD(ikp);
figure(1)
edges = linspace(min(lat_kp), max(lat_kp), 18);
% edges = min(lat_kp):10:max(lat_kp)+5;
[N,ibin] = histc(lat_kp,edges);
boxplot(mld_kp,ibin)
xticks(1:18)

xticklabels({'89.5S', '78.97S', '68.44S', '57.91S', '47.38S', '36.85S', ...
             '26.32S', '15.79S', '5.26S', '5.26N', '15.79N', '26.32N', ...
             '36.85N', '47.38N', '57.91N', '68.44N', '78.97N', '89.50N'});

for ji = 1:length(N) 
    ikp = find(ibin == ji);
    ave(ji) = mean(mld_kp(ikp));
    stdn(ji) = std(mld_kp(ikp));
end

figure(2)
inbetweenx = [1:length(edges), fliplr(1:length(edges))];
inbetweeny = [ave + stdn, fliplr(ave - stdn)];
fill(inbetweenx, inbetweeny,[0.9,0.9,0.9]);
hold on
plot(ave,':r^')
hold off
xticks(1:18)
xticklabels({'89.5S', '78.97S', '68.44S', '57.91S', '47.38S', '36.85S', ...
             '26.32S', '15.79S', '5.26S', '5.26N', '15.79N', '26.32N', ...
             '36.85N', '47.38N', '57.91N', '68.44N', '78.97N', '89.50N'});

图像位置的变换 (利用稀疏矩阵)

clc 
close all;
clear all
MOCK = imread('duck.tif');
keyboard
MOCK = MOCK(:,:,1);
MOCM = double(MOCK);
ikp = find(MOCM(:)<150);
[nx,ny] = size(MOCK);
tmp = sparse(nx,ny);
tmp(ikp) = MOCM(ikp);
MOCM = tmp;
spy(MOCM)

[ny,nx] =size(MOCK);
I = speye(ny*nx);
i0 = zeros(ny,nx);
i0(:) = 1:ny*nx;
ie = i0(:,[2:end,1]); iw = i0(:,[end,1:end-1]);
in = i0([2:end,1],:); is = i0([end,1:end-1],:);
% permuation operators
IE = I(ie(:),:); IW = I(iw(:),:);
IN = I(in(:),:); IS = I(is(:),:);
n = 1;
for k = 1:10*nx
    if n <= 100
        MOCM(:) = IE*MOCM(:);
    elseif n > 101 & n <=200
        MOCM(:) = IS*MOCM(:);
    elseif n > 201 & n <= 300
        MOCM(:) = IW*MOCM(:);
    elseif n > 301 & n <= 400
        MOCM(:) = IN*MOCM(:);
    end
    spy(MOCM); drawnow
    n = n + 1;
    if mod(k,400) == 0
        n = 1;
        MOCM = fliplr(MOCM);
    end 
end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值