A = xlsread('D:\data.xls');
%time = '2018-01-25';
%name = '凌海库'
%path = 'D:\grainData\';
%cloudTemperature(A,time,path,name,60,36,6.75,20,12,5);
%DrawCloud('D:\data.xls',time,path,name,60,36,6.75,20,12,5);
function DrawCloud(data,time,path,name,lengthx,lengthy,lengthh,xnum,ynum,znum)
A = xlsread(data);
cloudTemperature(A,time,path,name,lengthx,lengthy,lengthh,xnum,ynum,znum,'');
end
function cloudTemperature(B,TIME,path,name,lengthx,lengthy,lengthh,xnum,ynum,znum,T)
A = double(B);
lengthx = double(lengthx);
lengthy = double(lengthy);
lengthh = double(lengthh);
xnum = double(xnum);
ynum = double(ynum);
znum = double(znum);
intervalx = (lengthx-1)/(xnum-1);
intervaly = (lengthy-1)/(ynum-1);
time = TIME;
file = [path,name,'\',time];
%if ~exist(file)
% mkdir(file)
%end
colorbarTitle='温度';
junzhi = A(:);
junzhi(find(junzhi == 100)) = [];
desctwo=['平均粮温:',num2str(mean(junzhi(:))),'℃ 检测时间:',time];
%表格中有其他数据,替代为100,整行出现
A(find(A(:,1) == 100),:) = [];
colortype=1;
%这一块是进行原始数据与需要的坐标数据进行转换
for n = 1:znum
for j = 1:ynum
for i =1:xnum
D(i+xnum*(j-1),1)=intervalx*(i-1)+0.5;
D(i+xnum*(j-1),2)=intervaly*(j-1)+0.5;
D(i+xnum*(j-1),3)=A(ynum*znum-znum*j+n,xnum-i+1);
end
end
%剔除异常数据
index = 1:length(D(:,3));
D(index(find(D(:,3) == 100)),:) = [];
%画图的参数设定
coordinate1=[0 lengthx 0 lengthy -10 35];
pathFile1=[file,'\水平',num2str(n),'截面'];
imgTitle1=[name,time,'水平',num2str(n),'截面'];
yLabel1='由南向北(单位:米)';
xLabel1='由西向东(单位:米)';
pmtype1=1;
descone1=['截面最高温度:',num2str(max(D(:,3))),'℃ 截面最低温度:',num2str(min(D(:,3))),'℃ 截面平均温度:',num2str(mean(D(:,3))),'℃'];
%调用函数作图
%不同截面,例如其他非水平截面等,作图,方法类似
cloudgriddata(D,coordinate1,pathFile1,imgTitle1,colorbarTitle,xLabel1,yLabel1,colortype,descone1,desctwo,pmtype1,n,znum);
end
end
function cloudgriddata(data,coordinate,pathFile,imgTitle,colorbarTitle,xLabel,yLabel,colortype,desc,cfdesc,pmtype,N,numoffloor)
clear command history;
clf('reset'); %clf 清除图像窗口中当前图像,reset 重置所有对象设置,返回到最初默认状态。
set(gcf,'outerposition',get(0,'screensize')); %使图形窗口最大化
%set(gcf,'outerposition',[0,0,1600,900]);
set(gcf,'color','white','paperpositionmode','auto');
%set(gcf,'Position',[0,0,1600,900], 'color','w');
A=data;
x=A(:,1); %赋值
y=A(:,2);
z=A(:,3);
%subplot是将多个图画到一个平面上的工具。subplot(m,n,p)或者subplot(m n p),m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一列的,一共m行,如果m=2就是表示2行图。p表示图所在的位置,p=1表示从左到右从上到下的第一个位置。
subplot(4,3,1:9);
%插值自带v4方法,使用的是径向基r^0.5*log(r+1),光滑性不错,但外推能力很弱,若边界距最近测点距离较远,建议换其他方法
[X,Y,Z]=griddata(x,y,z,linspace(coordinate(1),coordinate(2))',linspace(coordinate(3),coordinate(4)),'V4');
%axes('position',[0.13,0.2,0.8,0.65]);
pcolor(X,Y,Z);
shading interp;%伪彩色图
hold on;
[c,h]=contourf(X,Y,Z,15,'linestyle','none'); %等高线图
p=clabel(c,h);
for n=p'
set(n,'string',sprintf('%.2f',get(n,'userdata')),'FontSize',14)
end
caxis([coordinate(5),coordinate(6)]);
if colortype==1
colormap jet;
elseif colortype==2
colormap jet;
elseif colortype==3
colormap jet;
end
h=colorbar;
set(get(h,'Title'),'string',colorbarTitle);
hold on;
plot(x,y,'.','MarkerEdgeColor','k',... %边界设置为黑色
'MarkerFaceColor','K',... %内部设置白色
'MarkerSize',15); %大小设置
title(imgTitle,'FontSize',18);
ylabel(yLabel,'FontSize',16);
xlabel(xLabel,'FontSize',16);
subplot(4,3,10:11);
text(0,0.8,desc,'FontSize',12,'HorizontalAlignment','left');
text(0,0.5,cfdesc,'FontSize',12,'HorizontalAlignment','left');
axis off;
%text('Units','pixels','Position',[0,-60],'String',desc,'FontSize',16);%设置单位为像素
%text('Units','pixels','Position',[0,-85],'String',cfdesc,'FontSize',16);%设置单位为像素
subplot(4,3,12);
x=[0 0 0;3 0 0;3 0 3;0 0 3];
y=[0 0 0;0 0 0;2 2 0;2 2 0];
z=[0 0 0;0 1 1;0 1 1;0 0 0];
x1=x(:,1);x2=x(:,2);x3=x(:,3);
y1=y(:,1);y2=y(:,2);y3=y(:,3);
z1=z(:,1);z2=z(:,2);z3=z(:,3);
fill3color=['w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w'];
fill3color(N) = 'y';
if pmtype==1
for i = 1:numoffloor
fill3(x1,y1,(z1+1-(i-1)/(numoffloor-1)),fill3color(i));
hold on;
end
text(-0.2,-0.4,'水平面','FontSize',12,'HorizontalAlignment','center');
elseif pmtype==3
for i = 1:numoffloor
fill3(x2,y2,(z2+1-(i-1)/(numoffloor-1)),fill3color(i));
hold on;
end
text(-0.2,-0.4,'东西垂直剖面','FontSize',12,'HorizontalAlignment','center');
elseif pmtype==2
for i = 1:numoffloor
fill3(x3,y3,(z3+1-(i-1)/(numoffloor-1)),fill3color(i));
hold on;
end
text(-0.2,-0.4,'南北垂直剖面','FontSize',12,'HorizontalAlignment','center');
end
axis off;
%set(gcf,'outerposition',[0,0,1600,900]);
set(gcf,'outerposition',get(0,'screensize'));
print(gcf,'-dpng',pathFile);
clear all;
end
%点图,这个是有些老师要求的,就是将各个位置点温度准确画到图上
function scatterone(data,coordinate,pathFile,imgTitle,xLabel,yLabel)
clear command history;
clf('reset'); %clf 清除图像窗口中当前图像,reset 重置所有对象设置,返回到最初默认状态。
set(gcf,'outerposition',get(0,'screensize')); %使图形窗口最大化
%set(gcf,'outerposition',[0,0,1600,900]);
set(gcf,'color','white','paperpositionmode','auto');
%set(gcf,'Position',[0,0,1600,900], 'color','w');
A=data;
x=A(:,1); %赋值
y=A(:,2);
z=A(:,3);
maxx = coordinate(2);
maxy = coordinate(4);
scatter(x,y,10,'k');
for i = 1:length(x)
text(x(i),y(i),[' ',num2str(z(i))])
end
hold on;
plot([0,maxx,maxx,0,0],[0,0,maxy,maxy,0],'color','black'); %大小设置
title(imgTitle,'FontSize',18);
ylabel(yLabel,'FontSize',16);
xlabel(xLabel,'FontSize',16);
axis off;
set(gcf,'outerposition',get(0,'screensize'));
print(gcf,'-dpng',[pathFile,'粮情数据分布点']);
clear all;
end
%二阶反向距离加权计算
function [Xq,Yq,Zq] = IDW(x,y,z,xq,yq)
[Yq,Xq] = meshgrid(yq,xq);
Zq = zeros(size(Xq));
xy = x(:) + y(:)*sqrt(-1);
weight(1:length(xy)) = 0;
for m = 1:length(yq)
for i = 1:length(xq)
d = abs(Xq(i,m) + Yq(i,m)*sqrt(-1) - xy);
mask = find(d == 0);
if isempty(mask)
DA = 0;
for j = 1:length(d)
DA = DA + 1/(d(j)^2);
end
for k = 1:length(d)
weight(k) = (1/(d(k)^2))/DA;
end
Zq(i,m) = weight * z;
else
Zq(i,m) = z(mask);
end
end
end
end
function cloudIWD(data,coordinate,pathFile,imgTitle,colorbarTitle,xLabel,yLabel,colortype,desc,cfdesc,pmtype,N,numoffloor)
clear command history;
clf('reset'); %clf 清除图像窗口中当前图像,reset 重置所有对象设置,返回到最初默认状态。
set(gcf,'outerposition',get(0,'screensize')); %使图形窗口最大化
%set(gcf,'outerposition',[0,0,1600,900]);
set(gcf,'color','white','paperpositionmode','auto');
%set(gcf,'Position',[0,0,1600,900], 'color','w');
A=data;
x=A(:,1); %赋值
y=A(:,2);
z=A(:,3);
%subplot是将多个图画到一个平面上的工具。subplot(m,n,p)或者subplot(m n p),m表示是图排成m行,n表示图排成n列,也就是整个figure中有n个图是排成一列的,一共m行,如果m=2就是表示2行图。p表示图所在的位置,p=1表示从左到右从上到下的第一个位置。
subplot(4,3,1:9);
x1 = linspace(coordinate(1),coordinate(2));
y1 = linspace(coordinate(3),coordinate(4));
[X,Y,Z] = IDW(x,y,z,x1,y1);
%axes('position',[0.13,0.2,0.8,0.65]);
pcolor(X,Y,Z);
shading interp;%伪彩色图
hold on;
[c,h]=contourf(X,Y,Z,15,'linestyle','none'); %等高线图
p=clabel(c,h);
for n=p'
set(n,'string',sprintf('%.2f',get(n,'userdata')),'FontSize',14)
end
caxis([coordinate(5),co
评论3