MATLAB Answers

0

How can I get a second x axis in my guide gui?

Asked by John Hunt on 16 Jul 2019
Latest activity Edited by John Hunt on 16 Jul 2019
I have a simple gui that is plotting 5 different plots from the same set of data. The x axis are all in position (mm), with different forces or torque as the y axis (see picture). I would like to add another x axis to the top two plots that are based on time (sec). (my current code affects the "green" plot "Average X-Force plot)
I am currently using the following code
% X Force Plot ONE OF MY PLOTS
axes(handles.xplot); % Select the plot that I want to visualize my data
cla; % clear the axes incase something was left
handles.xplot = gca; % get all of the values of the axes
ax1_pos = handles.xplot.Position; % get the position of the main axis
ax2 = axes('Position', ax1_pos, 'XAxisLocation', 'top', 'Color', 'none'); % Set the second axis
for i = 1:revs-1 % plot a point per "rotation" per my application
s = handles.dw.DefectiveWelds{1,1}{1,weldnum}{1,17}(i,1); % start of desired part of data set (I added it to my handles structure)
e = handles.dw.DefectiveWelds{1,1}{1,weldnum}{1,17}(i+1,1); % end of desired part of data set (to calculate the mean of the temperature and forc)e
time = handles.dw.DefectiveWelds{1,1}{1,(weldnum)}{1,1}(s,1); % Time vector of the data
xpos = handles.dw.DefectiveWelds{1,1}{1,(weldnum)}{1,2}(s,1); % x position vector of the data
avex = mean(handles.dw.DefectiveWelds{1,1}{1,(weldnum)}{1,10}(s:e,1)); % Average x force vector of the data
temp = mean(handles.dw.DefectiveWelds{1,1}{1,(weldnum)}{1,6}(s:e,1)); % Temperature vector of the data
plot(xpos ,avex,'*','Color',[76/255,153/255,0]) % plot the x position by the average x force in green
hold on % Hold on for second axis
plot(time ,avex,'Parent', ax2, 'Marker','*', 'Color', [76/255,153/255,0]) % Plot the same x force but by time (top axis)
hold on % Hold on to wait and plot the next point
end
title('Average X-Force (N)') % title for the plot
handles.xplot = gca; % Set the plot values for the gui
guidata(hObject,handles); % update the values
Thanks in advance
John

  0 Comments

Sign in to comment.

0 Answers