Advertisement
Guest User

geodata

a guest
Nov 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. function geodata
  2.  
  3. % SIMPLE_GUI2 Select a data set from the pop-up menu and display
  4. f = figure('Position',[200,200,450,350]);
  5.  
  6. h = [];
  7. % Construct the components.
  8. h(1) = uicontrol('Style','popupmenu',...
  9. 'String',{'Peaks','Membrane','Sinc', 'Wave', 'Float'},...
  10. 'Position',[335,20,100,25],...
  11. 'Callback',@popup_menu_Callback);
  12.  
  13. h(2) = axes('Units','pixels','Position',[50,30,255,255]);
  14.  
  15. % All buttons
  16. h(3) = uicontrol('Style', 'pushbutton', 'String', 'Rotate',...
  17. 'Position',[335,60,100,25], 'Callback', @rotate_button_Callback);
  18.  
  19. h(4) = uicontrol('Style', 'pushbutton', 'String', 'Top View',...
  20. 'Position', [335, 90, 100, 25], 'Callback', @top_view_Callback);
  21.  
  22. h(5) = uicontrol('Style', 'pushbutton', 'String', 'Side View 2',...
  23. 'Position', [335, 120, 100, 25], 'Callback', @side_view_2);
  24.  
  25. h(6) = uicontrol('Style', 'pushbutton', 'String', 'Side View 1',...
  26. 'Position', [335, 150, 100, 25], 'Callback', @side_view_1);
  27.  
  28. h(7) = uicontrol('Style', 'pushbutton', 'String', 'Stop Sound',...
  29. 'Position', [335, 190, 100, 25], 'Callback', @stop_music);
  30.  
  31. h(8) = uicontrol('Style', 'pushbutton', 'String', 'Play Sound',...
  32. 'Position', [335, 220, 100, 25], 'Callback', @play_music);
  33.  
  34. h(9) = uicontrol('Style', 'pushbutton', 'String', 'Stop',...
  35. 'Position', [335, 260, 100, 25], 'Callback', @stop_rot);
  36.  
  37. h(10) = uicontrol('Style', 'pushbutton', 'String', 'Start',...
  38. 'Position', [335, 290, 100, 25], 'Callback', @start_rot);
  39.  
  40.  
  41. % Rotation timer
  42. tmr = timer('ExecutionMode','FixedRate',...
  43. 'Period', 0.05, 'TimerFcn', @timer_Callback);
  44. tmr.TasksToExecute = 200;
  45.  
  46. % Assure resize automatically.
  47. f.Units = 'normalized';
  48. set(h, 'Units', 'normalized');
  49. set(h, 'FontSize', 12);
  50.  
  51. % Generate the data to plot.
  52. peaks_data = peaks(35);
  53. membrane_data = membrane;
  54. [x,y] = meshgrid(-8:.5:8);
  55. r = sqrt(x.^2+y.^2) + eps;
  56. sinc_data = sin(r)./r;
  57. t = 0:pi/10:2*pi;
  58. float_data = cylinder(2+cos(t));
  59.  
  60. % Audio components
  61. [xG,fs] = audioread('fanfare.wav');
  62. playtime = xG(1:fs*10); % play for 10 seconds
  63. recG = audioplayer(playtime,fs);
  64.  
  65. % Create a plot in the axes.
  66. s = surf(peaks_data);
  67.  
  68. % Play the music
  69. function play_music(source, eventdata)
  70. play(recG);
  71. end
  72.  
  73. % Stop the music
  74. function stop_music(source, eventdata)
  75. stop(recG);
  76. end
  77.  
  78.  
  79. % Rotate the graph
  80. function rotate_button_Callback(source, eventdata)
  81. direction = [0 0 1];
  82. rotate(s, direction, 5)
  83. end
  84.  
  85. angHori = 0; angVert = 0;
  86. % Top view
  87. function top_view_Callback(source, eventdata)
  88. angVert = 90; angHori = 0;
  89. view(angHori,angVert);
  90. end
  91.  
  92. % Side view no1
  93. function side_view_1(source, eventdata)
  94. angHori = 90; angVert = 0;
  95. view(angHori, angVert);
  96. end
  97.  
  98. % Side view no2
  99. function side_view_2(source, eventdata)
  100. angHori = 270; angVert = 0;
  101. view(angHori, angVert);
  102. end
  103.  
  104. % Timer rotation start
  105. function start_rot(source, eventdata)
  106. start(tmr);
  107. end
  108.  
  109. function timer_Callback(source, eventdata)
  110. direction = [0 0 1];
  111. rotate(s, direction, 1)
  112. end
  113.  
  114. % Timer rotation stop
  115. function stop_rot(source, eventdata)
  116. stop(tmr);
  117. end
  118.  
  119. % Pop-up menu callback. Read the pop-up menu Value property to
  120. function popup_menu_Callback(source,eventdata)
  121. % Determine the selected data set.
  122. str = get(source, 'String');
  123. val = get(source,'Value');
  124.  
  125. % Set current data to the selected data set.
  126. switch str{val}
  127. case 'Peaks' % User selects Peaks.
  128. s = surf(peaks_data);
  129. case 'Membrane'
  130. s = surf(membrane_data);
  131. case 'Sinc'
  132. s = surf(sinc_data);
  133. case 'Wave'
  134. [X,Y] = meshgrid(1:0.3:10,1:20);
  135. Z = sin(X) + cos(Y);
  136. s = surf(X,Y,Z);
  137. case 'Float'
  138. s = surf(float_data);
  139. end
  140.  
  141. end
  142.  
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement