📄 timeseriesviewer.m
字号:
% Add a context menu to each line
cmenu = uicontextmenu('Parent',handles.figure1);
set(lh,'UIContextMenu',cmenu);
% Define the context menu items
%Label Max and Min
item1 = uimenu(cmenu, 'Label', 'Label Max and Min', ...
'Callback', @localContextMenuCallback,'Tag','MaxMin');
%Label mean
item1 = uimenu(cmenu, 'Label', 'Label Mean', ...
'Callback', @localContextMenuCallback,'Tag','Mean');
%Plot derivative
item1 = uimenu(cmenu, 'Label', 'Plot derivative', ...
'Callback', @localContextMenuCallback,'Tag','Derivative');
%Find Value
item1 = uimenu(cmenu, 'Label', 'Find value', ...
'Callback', @localContextMenuCallback,'Tag','FindValue');
%Delete this line
item1 = uimenu(cmenu, 'Label', 'Delete', ...
'Callback', @localDeleteObject,'Separator','on');
case 'axes'
% Do nothing if dropping axes on itself
if drag==drop
return
end;
% Get all children of drag axes
dragkids = get(drag,'Children');
dragmenus = get(dragkids,'UIContextMenu');
if ~iscell(dragmenus), dragmenus = {dragmenus};end;
if iscell(dragkids)
dragkids = cell2mat(dragkids);
end;
% Get all children of drop axes
dropkids = get(drop,'Children');
dropmenus = get(dropkids,'UIContextMenu');
if iscell(dropkids)
dropkids = cell2mat(dropkids);
end;
if ~iscell(dropmenus), dropmenus = {dropmenus};end;
% Swap children
hgS_drag = handle2struct(dragkids);
hgS_drop = handle2struct(dropkids);
% Delete kids
delete(dragkids)
delete(dropkids)
% Add children to axes
newdropkids = struct2handle(hgS_drag,drop);
set(newdropkids,{'UIContextMenu'},dragmenus)
newdragkids = struct2handle(hgS_drop,drag);
set(newdragkids,{'UIContextMenu'},dropmenus)
% Update parameter list of axes
dragparms = getappdata(drag,'Parameters');
dropparms = getappdata(drop,'Parameters');
setappdata(drop,'Parameters',dragparms);
parms = getappdata(drop,'Parameters');
setappdata(drag,'Parameters',dropparms);
% Update legend on drop axes
localUpdateLegend(drop)
localUpdateLegend(drag)
end;
end;
% --- Executes during object creation, after setting all properties. function NoAxesEdit_CreateFcn(hObject, eventdata, handles) % hObject handle to NoAxesEdit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function NoAxesEdit_Callback(hObject, eventdata, handles) % hObject handle to NoAxesEdit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of NoAxesEdit as text % str2double(get(hObject,'String')) returns contents of NoAxesEdit as a double % Adjust the number of visible axes
% Error check - must be number between 1 and 4
% --- Executes during object creation, after setting all properties. function NoAxesCombo_CreateFcn(hObject, eventdata, handles) % hObject handle to NoAxesCombo (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1;
% Set slider to gray, edit box to white
switch get(hObject,'style')
case 'slider' if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end case 'edit'
set(hObject,'BackgroundColor',[1 1 1]);
end;
% --- Executes on slider movement. function NoAxesCombo_Callback(hObject, eventdata, handles) % hObject handle to NoAxesCombo (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
%I've created my own combobox - combining an edit box and a slider. I gave
%them both the same handle so that they would share a callback
sl = handles.NoAxesCombo(1); %Slider handle
ed = handles.NoAxesCombo(2); %Edit handle
if hObject==sl %Slider
NoAx = round(get(sl,'Value'));
set(ed,'String',num2str(NoAx));
else %Edit
NoAx = str2num(get(hObject,'String'));
if isempty(NoAx)
NoAx=1;
set(hObject,'String','1');
end;
NoAx = round(NoAx);
if NoAx<1
NoAx = 1;
set(hObject,'String','1');
elseif NoAx>4
NoAx = 4;
set(hObject,'String','4');
end;
end;
% Set the selected number of axes visible
ax = handles.axes; %Handles to axes
set(ax(1:NoAx),'Visible','on',{'Position'},handles.axpos{NoAx}); %First NoAx are visible
set(ax(NoAx+1:end),'Visible','off'); %The rest (if any) are not
% Show XTicks on bottom axes only
% set(ax(1:NoAx-1),'XTick',[]);
localZoomCallback(handles.figure1);
% Set the children of only the visible axes to be visible
showkids = get(ax(1:NoAx),'Children');
if iscell(showkids)
showkids = cell2mat(showkids);
end;
hidekids = get(ax(NoAx+1:end),'Children');
if iscell(hidekids)
hidekids = cell2mat(hidekids);
end;
set(showkids,'visible','on');
set(hidekids,'visible','off');
% Reset the legends
for ii=1:4
legend(ax(ii),'off');
end;
for ii=1:NoAx
if isappdata(ax(ii),'Parameters');
parms = getappdata(ax(ii),'Parameters');
if ~isempty(parms)
legend(ax(ii),parms)
end;
end;
end;
% Reset the dragndrop targets to just the visible axes. This will also
% update the positions.
% handles.dd = set(handles.dd,'DropHandles',[ax(1:NoAx) handles.TimeSelectPopup]);
handles.dd = set(handles.dd,'DropHandles',[ax(1:NoAx) handles.AddTimeVectorsFrame]);
guidata(handles.figure1,handles);
% Set the positions
%
% %Some fun and games to get a decent array of handles to children of each
% %axes
% ax1kids = get(ax1,'Children');
% ax1kids = ax1kids';
% ax2kids = get(ax2,'Children');ax2kids = cell2mat(ax2kids)';
% ax3kids = get(ax3,'Children');ax3kids = cell2mat(ax3kids)';
% ax4kids = get(ax4,'Children');ax4kids = cell2mat(ax4kids)';
%
% %Delete all legends. Add a new one when axes become visible
% delete(findobj(handles.figure1,'Type','Axes','Tag','legend'));
%
% if isempty(ax1kids)
% ax1kids = [];
% end;
% if isempty(ax2kids)
% ax2kids = [];
% end;
% if isempty(ax3kids)
% ax3kids = [];
% end;
% if isempty(ax4kids)
% ax4kids = [];
% end;
%
%
% switch NoAx
% case 1
% set([ax1 ax1kids],'Visible','on');
% set([ax2 ax3 ax4 ax2kids ax3kids ax4kids],'Visible','off');
% % legend([ax2 ax3 ax4],'hide');
% % legend(ax1,'show')
% legend(ax1,getappdata(ax1,'Parameters'))
% case 2
% set([ax2 ax2kids],'Visible','on');
% set([ax1 ax3 ax4 ax1kids ax3kids ax4kids],'Visible','off');
% % legend([ax1 ax3 ax4],'hide');
% % legend(ax2,'show')
% for ii=1:2
% if isappdata(ax2(ii),'Parameters');
% legend(ax2(ii),getappdata(ax2(ii),'Parameters'))
% end;
% end;
% case 3
% set([ax3 ax3kids],'Visible','on');
% set([ax1 ax2 ax4 ax1kids ax2kids ax4kids],'Visible','off');
% % legend([ax1 ax2 ax4],'hide');
% % legend(ax3,'show')
% for ii=1:3
% if isappdata(ax3(ii),'Parameters');
% legend(ax3(ii),getappdata(ax3(ii),'Parameters'))
% end;
% end;
% case 4
% set([ax4 ax4kids],'Visible','on');
% set([ax1 ax2 ax3 ax1kids ax2kids ax3kids],'Visible','off');
% % legend([ax1 ax2 ax3],'hide');
% % legend(ax4,'show')
% for ii=1:4
% if isappdata(ax4(ii),'Parameters');
% legend(ax4(ii),getappdata(ax4(ii),'Parameters'))
% end;
% end;
% end;
%
%
% --- Executes on button press in ZoomButton. function ZoomButton_Callback(hObject, eventdata, handles) % hObject handle to ZoomButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
val = get(hObject,'Value');
if val
%Turn off datalabels
set(handles.DataLabelButton,'Value',0);
datalabel off
%Turn off cursors
set(handles.CursorButton,'Value',0)
eventlabel off
%Turn on zoom
linkedzoom(handles.axes,'onx',{@localZoomCallback,handles.figure1});
% Reset legends - they get hidden by linkedzoom
for ii=1:4
localUpdateLegend(handles.axes(ii));
end;
else
% Turn off zoom
linkedzoom off
% Reset axis limits
localTurnOffZoom(handles);
end;
% --- Executes on button press in DataLabelButton. function DataLabelButton_Callback(hObject, eventdata, handles) % hObject handle to DataLabelButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) val = get(hObject,'Value');
if val
%Turn off zoom
set(handles.ZoomButton,'Value',0);
linkedzoom off
% Reset axis limits
localTurnOffZoom(handles);
%Turn off event labels
set(handles.CursorButton,'Value',0)
eventlabel off
%Turn on datalabels
datalabel on
else
datalabel off
end;
% --- Executes on button press in CursorButton. function CursorButton_Callback(hObject, eventdata, handles) % hObject handle to CursorButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of CursorButton val = get(hObject,'Value');
if val
%Turn off datalabels
set(handles.DataLabelButton,'Value',0);
datalabel off
% Reset axis limits
localTurnOffZoom(handles);
%Turn off zoom
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -