Advertisement
Guest User

Untitled

a guest
May 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.53 KB | None | 0 0
  1. function varargout = zad_4(varargin)
  2. % ZAD_4 MATLAB code for zad_4.fig
  3. %      ZAD_4, by itself, creates a new ZAD_4 or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = ZAD_4 returns the handle to a new ZAD_4 or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      ZAD_4('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in ZAD_4.M with the given input arguments.
  11. %
  12. %      ZAD_4('Property','Value',...) creates a new ZAD_4 or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before zad_4_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to zad_4_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22.  
  23. % Edit the above text to modify the response to help zad_4
  24.  
  25. % Last Modified by GUIDE v2.5 30-May-2016 18:15:49
  26.  
  27. % Begin initialization code - DO NOT EDIT
  28. gui_Singleton = 1;
  29. gui_State = struct('gui_Name',       mfilename, ...
  30.                    'gui_Singleton',  gui_Singleton, ...
  31.                    'gui_OpeningFcn', @zad_4_OpeningFcn, ...
  32.                    'gui_OutputFcn',  @zad_4_OutputFcn, ...
  33.                    'gui_LayoutFcn',  [] , ...
  34.                    'gui_Callback',   []);
  35. if nargin && ischar(varargin{1})
  36.     gui_State.gui_Callback = str2func(varargin{1});
  37. end
  38.  
  39. if nargout
  40.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  41. else
  42.     gui_mainfcn(gui_State, varargin{:});
  43. end
  44.  
  45. % End initialization code - DO NOT EDIT
  46.  
  47. function zad_4_OpeningFcn(hObject, eventdata, handles, varargin)
  48.  
  49. handles.output = hObject;
  50.  
  51. guidata(hObject, handles);
  52.  
  53. % city Kamennomostskiy
  54. lat = 44.300703;
  55. lon = 40.183990;
  56.  
  57. terrain = getTerrain(lat,lon);
  58. minHeight = -499;
  59. maxHeight = 3500;
  60.  
  61. colMat = [
  62. 0.0 0.0 0.7
  63. 0.0 0.8 0.0
  64. 0.0 1.0 0.0
  65. 1.0 1.0 0.0
  66. 1.0 0.8 0.0
  67. 1.0 0.0 0.0
  68. 0.7 0.0 0.0
  69. 0.4 0.0 0.0 ];
  70.  
  71. delta = 0.8365;
  72. lat_s = lat - delta;
  73. lon_s = lon - delta;
  74. latPoints = [ceil(lat) floor(lat)];
  75. lonPoints = [floor(lon) ceil(lon)];
  76.  
  77. lat_diff = 201-(latPoints - lat_s)*100/delta;
  78. lon_diff = (lonPoints - lon_s)*100/delta;
  79.  
  80. axes(handles.axes1);
  81. imagesc(terrain, [minHeight maxHeight]);
  82. colormap(colMat);
  83. colorbar;
  84.  
  85. xLabelName='Longitude °';
  86. yLabelName='Latitude °';
  87. xlabel(xLabelName);
  88. ylabel(yLabelName);
  89.  
  90. set(gca,'XGrid','on','YGrid','on','XTickLabel',lonPoints,'XTick',lon_diff,'YTickLabel',latPoints,'YTick',lat_diff);
  91. hold on;
  92. plot(101,101,'ko');
  93. text(105,101,'Kamennomostskiy','Color','Black');
  94.  
  95.  
  96. % --- Outputs from this function are returned to the command line.
  97. function varargout = zad_4_OutputFcn(hObject, eventdata, handles)
  98. % varargout  cell array for returning output args (see VARARGOUT);
  99. % hObject    handle to figure
  100. % eventdata  reserved - to be defined in a future version of MATLAB
  101. % handles    structure with handles and user data (see GUIDATA)
  102.  
  103. % Get default command line output from handles structure
  104. varargout{1} = handles.output;
  105.  
  106.  
  107. function terrain = getTerrain(lat, lon)
  108. pixelsPerDegree = 120;
  109. columns = 4800;
  110.  
  111. dLAT = 90 - lat;
  112. dLON = 20 + lon;
  113.  
  114. x = round(dLON * pixelsPerDegree) - 100;
  115. y = round(dLAT * pixelsPerDegree) - 100;
  116.  
  117. f = fopen('E020N90.DEM', 'r');
  118. terrain = zeros(201, 201, 'double');
  119.  
  120. for i = 1 : 201
  121.    fseek(f, ((y + i) * columns + x ) * 2, 'bof');
  122.    terrain(i, :) = fread(f, 201, 'int16', 0, 'b');
  123. end
  124.  
  125. fclose(f);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement