| function ShowGridLine(lon,lat,NSkip,LineC,LineS,LineM) % To show a 2d mesh-grid defined by given grid points % similar to the function mesh? % Example: % ShowGridLine(lon,lat,2,'k','-','.') % http://scriptdemo.blogspot.com % if (nargin>3) if exist('LineC','var')~=1 LineC='k'; end if exist('LineS','var')~=1 LineS='-'; end if exist('LineM','var')~=1 LineM='none'; end elseif (nargin>=2) if exist('NSkip','var')==1 if ischar(NSkip) LineC=NSkip; clear NSkip; end end if exist('NSkip','var')~=1 NSkip=5; end if exist('LineC','var')~=1 LineC='k'; end if exist('LineS','var')~=1 LineS='-'; end if exist('LineM','var')~=1 LineM='none'; end elseif (nargin==0) close all; [xx,yy]=meshgrid(1:19,1:19); ShowGridLine(xx,yy,1,'k','-'); plot(4,4,'o','markerfacecolor','k','markersize',4,'markeredgecolor','k'); plot(16,16,'o','markerfacecolor','k','markersize',4,'markeredgecolor','k'); plot(4,16,'o','markerfacecolor','k','markersize',4,'markeredgecolor','k'); plot(16,4,'o','markerfacecolor','k','markersize',4,'markeredgecolor','k'); set(gcf,'color','w'); set(gca,'xtick',2:2:18,'ytick',2:2:18,'ydir','r','xaxislocation','top') axis equal; axis tight; xlabel('Go Board','fontweight','bold','fontsize',18,'color','red'); return else help ShowGridLine return end [N1,N2]=size(lat); if ~ishold hold on; end for NL=1:NSkip:N2 hp=plot(lon(:,NL),lat(:,NL)); set(hp,'color',LineC,'linestyle',LineS,'Marker',LineM) end for NL=1:NSkip:N1 hp=plot(lon(NL,:),lat(NL,:)); set(hp,'color',LineC,'linestyle',LineS,'Marker',LineM,'tag','gridLines') end |
Showing posts with label mesh. Show all posts
Showing posts with label mesh. Show all posts
Friday, August 24, 2012
[Matlab] show 2d mesh grid
Sunday, February 5, 2012
[Matlab] Convert a 2D mesh to a single kml file
| function mesh2kml(kmlfile,long,lat,iskip,jskip) % convert a 2D mesh grid into a single plain kml file % will create the horizontal and vertical mesh-line seperately % usage: % mesh2kml(kml-filename,longitude,latitude [iskip, jskip]) % iskip: reduce the points when to generate i-direction-mesh-line % jskip: reduce the points when to generate j-direction-mesh-line % e.g., % lon=-90:2:20; % lat=37:65; % [lon,lat]=meshgrid(lon,lat); % mesh2kml('mesh2kml_test',lon,lat,1,1); % will produce a kml file named mesh2kml_test in current folder % % http://scriptdemo.blogspot.com if nargin<3 help mesh2kml return end if nargin==3 iskip=5; jskip=5; elseif nargin==4 jskip=5; end fid=fopen([kmlfile,'.kml'],'wt'); writekmlHeader(fid,kmlfile); if length(long)~=numel(long) % mesh [NY,NX]=size(long); %i-index longUD=flipud(long); latUD=flipud(lat); longI=long; latI=lat; longI(:,2:2:end)=longUD(:,2:2:end); latI(:,2:2:end)=latUD(:,2:2:end); clear longUD latUD jindex=sort(unique([1 jskip:jskip:NY NY])); longI=reshape(longI(jindex,:),1,[]); latI=reshape(latI(jindex,:),1,[]); fprintf(fid,'%s \n','<Placemark>'); fprintf(fid,'%s \n',['<name>',kmlfile,'-I</name>']); fprintf(fid,'%s \n','<LineString>'); fprintf(fid,'%s \n','<tessellate>1</tessellate>'); % fprintf(fid,'%s \n','<coordinates>'); fprintf(fid,'%0.6f,%0.6f,0.0 \n', [longI;latI]); fprintf(fid,'%s \n','</coordinates>'); fprintf(fid,'%s \n','</LineString>'); fprintf(fid,'%s \n','</Placemark>'); %j-index longLR=fliplr(long); latLR=fliplr(lat); longJ=long; latJ=lat; longJ(2:2:end,:)=longLR(2:2:end,:); latJ(2:2:end,:)=latLR(2:2:end,:); clear longLR latLR longJ=longJ'; latJ=latJ'; iindex=sort(unique([1 iskip:iskip:NX NX])); longJ=reshape(longJ(iindex,:),1,[]); latJ=reshape(latJ(iindex,:),1,[]); fprintf(fid,'%s \n','<Placemark>'); fprintf(fid,'%s \n',['<name>',kmlfile,'-J</name>']); fprintf(fid,'%s \n','<LineString>'); fprintf(fid,'%s \n','<tessellate>1</tessellate>'); % fprintf(fid,'%s \n','<coordinates>'); fprintf(fid,'%0.6f,%0.6f,0.0 \n', [longJ;latJ]); fprintf(fid,'%s \n','</coordinates>'); fprintf(fid,'%s \n','</LineString>'); fprintf(fid,'%s \n','</Placemark>'); else long=reshape(long,1,[]); lat=reshape(lat,1,[]); fprintf(fid,'%s \n','<Placemark>'); fprintf(fid,'%s \n',['<name>',kmlfile,'</name>']); fprintf(fid,'%s \n','<LineString>'); fprintf(fid,'%s \n','<tessellate>1</tessellate>'); % fprintf(fid,'%s \n','<coordinates>'); fprintf(fid,'%0.6f,%0.6f,0.0 \n', [long;lat]); fprintf(fid,'%s \n','</coordinates>'); fprintf(fid,'%s \n','</LineString>'); fprintf(fid,'%s \n','</Placemark>'); end writekmlEnd(fid); fclose(fid); function writekmlHeader(fid,kmlName) fprintf(fid,'%s \n','<?xml version="1.0" encoding="UTF-8"?>'); fprintf(fid,'%s','<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" '); fprintf(fid,'%s \n','xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">'); fprintf(fid,'%s \n','<Document>'); fprintf(fid,'%s \n',['<name>',kmlName,'.kml</name>']); function writekmlEnd(fid) fprintf(fid,'%s \n','</Document>'); fprintf(fid,'%s \n','</kml>'); |
Subscribe to:
Posts (Atom)
