Passing data from External function to main GUIDE function
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I've a function in GUIDE that goes:
% --- Executes on button press in plot2_push.
function plot2_push_Callback(hObject, eventdata, handles)
% hObject handle to plot2_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.time_sec2 = 1:size(handles.selected_file_table(:,'t'));
for i = 1:handles.count2;
plot(handles.axes2, handles.time_sec2, table2array(handles.selected_file_table(:,handles.selected_varlist2.String(i))),'LineWidth',2);
(handles.selected_file_table(:,handles.selected_varlist2.String(i))),'LineWidth',2);
axes(handles.axes2); hold on
end
grid(handles.axes2,'on');
handles.axes2.XMinorGrid = 'on';
handles.axes2.YMinorGrid = 'on';
hold off
set(handles.axes2,'Color',[0.87058824300766 0.921568632125854 0.980392158031464],...
'XColor',[0 0 0],'YColor',[0 0 0],'ZColor',[0 0 0]);
legend(handles.selected_varlist2.String,'Location','northoutside','Orientation','horizontal')
linkaxes([handles.axes1,handles.axes2],'x')
vertical_cursors1;
guidata(hObject, handles);
In the last line, I'm calling an external function to plot cursors (by Jiro) that goes like this:
function vertical_cursors1
set(gcf, ...
'WindowButtonDownFcn', @clickFcn, ...
'WindowButtonUpFcn', @unclickFcn);
% Set up cursor text
allLines = findobj(gcf, 'type', 'line');
hText = nan(1, length(allLines));
for id = 1:length(allLines)
hText(id) = text(NaN, NaN, '', ...
'Parent', get(allLines(id), 'Parent'), ...
'BackgroundColor', 'yellow', ...
'Color', get(allLines(id), 'Color'));
end
% Set up cursor lines
allAxes = findobj(gcf, 'Type', 'axes');
hCur = nan(1, length(allAxes));
for id = 1:length(allAxes)
hCur(id) = line([NaN NaN], ylim(allAxes(id)), ... %%hCur are cursor lines
'Color', 'black', 'Parent', allAxes(id));
end
function clickFcn(varargin)
% Initiate cursor if clicked anywhere but the figure
if strcmpi(get(gco, 'type'), 'figure')
set(hCur, 'XData', [NaN NaN]); % <-- EDIT
set(hText, 'Position', [NaN NaN]); % <-- EDIT
else
set(gcf, 'WindowButtonMotionFcn', @dragFcn)
[b, curtime1] = dragFcn();
disp(b); disp(curtime1);
end
end
function [yall,xtime] = dragFcn(varargin)
% Get mouse location
pt = get(gca, 'CurrentPoint');
% Update cursor line position
xtime = pt(1);
set(hCur, 'XData', [pt(1), pt(1)]);
% Update cursor text
yall = zeros(1,length(allLines));
for idx = 1:length(allLines) % allLines refering to each line
xdata = get(allLines(idx), 'XData'); % the x points for line #idx
ydata = get(allLines(idx), 'YData'); % the y points for line #idx
if pt(1) >= xdata(1) && pt(1) <= xdata(end)
y = interp1(xdata, ydata, pt(1));
% disp(y)
set(hText(idx), 'Position', [pt(1), y], ...
'String', sprintf('(%0.2f, %0.2f)', pt(1), y));
yall(:,idx) = y;
else
set(hText(idx), 'Position', [NaN NaN]);
end
end
end
function unclickFcn(varargin)
set(gcf, 'WindowButtonMotionFcn', '');
end
end
I've tried to pass data of 'yall' to the main GUI function but to no avail. Can someone help me?
Thanks.
2 comentarios
Geoff Hayes
el 11 de Abr. de 2016
James - how do you expect to use the yall data? Will you be collecting it an array? At which point will you then use this data? You can try saving it to the handles structure which would be accessible by the other callbacks. Please provide more context.
Respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!