Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function geodata
- % SIMPLE_GUI2 Select a data set from the pop-up menu and display
- f = figure('Position',[200,200,450,350]);
- h = [];
- % Construct the components.
- h(1) = uicontrol('Style','popupmenu',...
- 'String',{'Peaks','Membrane','Sinc', 'Wave', 'Float'},...
- 'Position',[335,20,100,25],...
- 'Callback',@popup_menu_Callback);
- h(2) = axes('Units','pixels','Position',[50,30,255,255]);
- % All buttons
- h(3) = uicontrol('Style', 'pushbutton', 'String', 'Rotate',...
- 'Position',[335,60,100,25], 'Callback', @rotate_button_Callback);
- h(4) = uicontrol('Style', 'pushbutton', 'String', 'Top View',...
- 'Position', [335, 90, 100, 25], 'Callback', @top_view_Callback);
- h(5) = uicontrol('Style', 'pushbutton', 'String', 'Side View 2',...
- 'Position', [335, 120, 100, 25], 'Callback', @side_view_2);
- h(6) = uicontrol('Style', 'pushbutton', 'String', 'Side View 1',...
- 'Position', [335, 150, 100, 25], 'Callback', @side_view_1);
- h(7) = uicontrol('Style', 'pushbutton', 'String', 'Stop Sound',...
- 'Position', [335, 190, 100, 25], 'Callback', @stop_music);
- h(8) = uicontrol('Style', 'pushbutton', 'String', 'Play Sound',...
- 'Position', [335, 220, 100, 25], 'Callback', @play_music);
- h(9) = uicontrol('Style', 'pushbutton', 'String', 'Stop',...
- 'Position', [335, 260, 100, 25], 'Callback', @stop_rot);
- h(10) = uicontrol('Style', 'pushbutton', 'String', 'Start',...
- 'Position', [335, 290, 100, 25], 'Callback', @start_rot);
- % Rotation timer
- tmr = timer('ExecutionMode','FixedRate',...
- 'Period', 0.05, 'TimerFcn', @timer_Callback);
- tmr.TasksToExecute = 200;
- % Assure resize automatically.
- f.Units = 'normalized';
- set(h, 'Units', 'normalized');
- set(h, 'FontSize', 12);
- % Generate the data to plot.
- peaks_data = peaks(35);
- membrane_data = membrane;
- [x,y] = meshgrid(-8:.5:8);
- r = sqrt(x.^2+y.^2) + eps;
- sinc_data = sin(r)./r;
- t = 0:pi/10:2*pi;
- float_data = cylinder(2+cos(t));
- % Audio components
- [xG,fs] = audioread('fanfare.wav');
- playtime = xG(1:fs*10); % play for 10 seconds
- recG = audioplayer(playtime,fs);
- % Create a plot in the axes.
- s = surf(peaks_data);
- % Play the music
- function play_music(source, eventdata)
- play(recG);
- end
- % Stop the music
- function stop_music(source, eventdata)
- stop(recG);
- end
- % Rotate the graph
- function rotate_button_Callback(source, eventdata)
- direction = [0 0 1];
- rotate(s, direction, 5)
- end
- angHori = 0; angVert = 0;
- % Top view
- function top_view_Callback(source, eventdata)
- angVert = 90; angHori = 0;
- view(angHori,angVert);
- end
- % Side view no1
- function side_view_1(source, eventdata)
- angHori = 90; angVert = 0;
- view(angHori, angVert);
- end
- % Side view no2
- function side_view_2(source, eventdata)
- angHori = 270; angVert = 0;
- view(angHori, angVert);
- end
- % Timer rotation start
- function start_rot(source, eventdata)
- start(tmr);
- end
- function timer_Callback(source, eventdata)
- direction = [0 0 1];
- rotate(s, direction, 1)
- end
- % Timer rotation stop
- function stop_rot(source, eventdata)
- stop(tmr);
- end
- % Pop-up menu callback. Read the pop-up menu Value property to
- function popup_menu_Callback(source,eventdata)
- % Determine the selected data set.
- str = get(source, 'String');
- val = get(source,'Value');
- % Set current data to the selected data set.
- switch str{val}
- case 'Peaks' % User selects Peaks.
- s = surf(peaks_data);
- case 'Membrane'
- s = surf(membrane_data);
- case 'Sinc'
- s = surf(sinc_data);
- case 'Wave'
- [X,Y] = meshgrid(1:0.3:10,1:20);
- Z = sin(X) + cos(Y);
- s = surf(X,Y,Z);
- case 'Float'
- s = surf(float_data);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement