📄 xferplot.m
字号:
% Just return a quick empty:
if isempty(style),
h=[]; return;
end
block_data = get_param(blk,'UserData');
hfig = block_data.hfig;
fig_data = get(hfig,'UserData');
% Get handles to just one of the options menu line style items.
% The context (and other line #) menus simply contain redundant info.
%
hmenus = fig_data.menu.linestyle; % [options;context] x [line1 line2 ...]
hstyles = get(hmenus(:,lineNum),'child'); % style menu items for lineNum menu, options/context
hstyles = cat(2,hstyles{:}); % matrix of handles: styles x [options context]
menuStyles = get(hstyles(:,1),'UserData'); % cell array of style strings just for options menu
h = []; % in case no match is found
for i=1:size(hstyles,1),
if isequal(style, menuStyles{i}),
% Found a matching style entry
% Return both Options and Context menu handles for
% corresponding style entry for line number lineNum
h = hstyles(i,:);
return;
end
end
% ---------------------------------------------------------------
function h = getColorMenuHandlesFromRGB(blk, lineNum, rgb)
% Maps an RGB color spec to a color menu index.
% The userdata fields of color menu objects contain RGB specs.
% Returns an empty handle vector if no match is found.
% If RGB is empty, we won't find any match
% Just return a quick empty:
if isempty(rgb),
h=[]; return;
end
block_data = get_param(blk,'UserData');
hfig = block_data.hfig;
fig_data = get(hfig,'UserData');
% Get handles to just one of the options menu line color items.
% The context (and other line #) menus simply contain redundant info.
%
hmenus = fig_data.menu.linecolor; % [options;context] x [line1 line2 ...]
hclrs = get(hmenus(:,lineNum),'child'); % color menu items for lineNum menu, options/context
hclrs = cat(2,hclrs{:}); % matrix of handles: colors x [options context]
menuRGB = get(hclrs(:,1),'UserData'); % cell array of RGB vectors just for options menu
h = []; % in case no match is found
for i=1:size(hclrs,1),
if isequal(rgb, menuRGB{i}),
% Found a matching RGB entry
% Return both Options and Context menu handles for
% corresponding color entry for line number lineNum
h = hclrs(i,:);
return;
end
end
% ---------------------------------------------------------------
function rgb = mapCSpecToRGB(blk, user_cspec)
% Maps a user-defined color spec (CSpec) to an RGB triple
% An empty string maps to black (so unspecified lines are simply black)
% User-define color spec can be 'r' or 'red' or [1 0 0], etc.
% If user-spec is an empty, it is mapped to black
if isempty(user_cspec),
rgb=[0 0 0]; % black
return;
end
% If user-spec is an RGB triple encoded as a string,
% convert to numeric and return:
rgb = str2num(user_cspec);
if ~isempty(rgb),
return;
end
% User spec is not an RGB triple.
% As a favor to the user, remove any apostrophes from the spec.
% The user might have accidentally entered:
% 'c'|'y' (for example)
% instead of
% c|y (which is what is required since this is a 'literal' edit box)
%
% If any apostrophes were detected, remove them:
i = find(user_cspec == '''');
if ~isempty(i),
user_cspec(i)=''; % remove apostrophes
%warning('Channel color specs are literal strings - do not use apostrophes.');
end
% If user-defined color spec is invalid, return an empty
block_data = get_param(blk,'UserData');
hcspec = block_data.hcspec;
try
set(hcspec,'color',user_cspec);
rgb = get(hcspec,'color');
catch
warning('Invalid line color specified.');
rgb = zeros(0,3); % empty RGB spec
end
% ---------------------------------------------------------------
function [rgb,h] = getDialogLineColor(blk,lineNum)
% Determine RGB vector corresponding to user-specified color.
% - If user-specified color is empty, black is substituted.
% - If user-specified color is not found, RGB is set to empty.
%
% Optionally returns vector of 2 handles, H, for corresponding
% line color menu items in the Options and Context menus.
pipestr = get_param(blk,'LineColors'); % get all user-specified color specs
user_cspec = get_pipestr(pipestr,lineNum,1); % cspec for line lineNum
rgb = mapCSpecToRGB(blk, user_cspec); % find RGB representation - empty if no match
if nargout>1,
h = getColorMenuHandlesFromRGB(blk, lineNum, rgb); % get handles - may be empty
end
% ---------------------------------------------------------------
function [style,h] = getDialogLineStyle(blk,lineNum)
% Determine style string corresponding to user-specified color.
% - If user-specified style is empty, solid is substituted.
% - If user-specified style is not found, style is set to empty.
%
% Optionally returns vector of 2 handles, H, for corresponding
% line style menu items in the Options and Context menus.
pipestr = get_param(blk,'LineStyles'); % get all user-specified style specs
style = get_pipestr(pipestr,lineNum,1); % style for line lineNum
% Map from user-specified style to actual style string:
if isempty(style),
style='-';
end
h = getStyleMenuHandlesFromStyle(blk, lineNum, style); % get handles - may be empty
% ---------------------------------------------------------------
function y = anyStemMarkers(blk)
% Determine if any lines have a Stem marker selected
block_data = get_param(blk,'UserData');
nchans = block_data.NChans;
pipestr = get_param(blk,'LineMarkers'); % get all user-specified marker specs
y = 0; % assume no stem markers selected
for lineNum=1:nchans,
marker = get_pipestr(pipestr, lineNum,1);
y = strcmp(marker,'stem');
if y, return; end
end
% ---------------------------------------------------------------
function [marker,h] = getDialogLineMarker(blk,lineNum)
% Determine RGB vector corresponding to user-specified color.
% - If user-specified marker is empty, 'none' is substituted.
% - If user-specified marker is not found, marker is set to empty.
%
% Optionally returns vector of 2 handles, H, for corresponding
% line marker menu items in the Options and Context menus.
pipestr = get_param(blk,'LineMarkers'); % get all user-specified marker specs
marker = get_pipestr(pipestr,lineNum,1); % marker for line lineNum
% Map from user-specified marker to actual style string:
if isempty(marker),
marker='None';
end
h = getMarkerMenuHandlesFromMarker(blk, lineNum, marker); % get handles - may be empty
% ---------------------------------------------------------------
function [disable,h] = getDialogLineDisable(blk,lineNum)
% Determine channel disable setting
%
% Optionally returns vector of 2 handles, H, for corresponding
% line marker menu items in the Options and Context menus.
pipestr = get_param(blk,'LineDisables'); % get all user-specified disable specs
disable = get_pipestr(pipestr,lineNum,1); % disable for line lineNum
% Map from user-specified disable to actual disable string:
if isempty(disable),
disable='on';
end
h = getDisableMenuHandles(blk, lineNum);
% ---------------------------------------------------------------
function SetMenuChecks(blk)
% Called only from first_update to preset menu checks
% blk: masked subsystem block
block_data = get_param(blk,'UserData');
fig_data = get(block_data.hfig,'UserData');
% Update AxisGrid menu check:
%
opt = get_param(blk,'AxisGrid');
set(fig_data.menu.axisgrid, 'Checked',opt);
% Update AxisZoom menu check:
%
opt = get_param(blk,'AxisZoom');
set(fig_data.menu.axiszoom, 'Checked',opt);
% Update Frame Number menu check:
%
opt = get_param(blk,'FrameNumber');
set(fig_data.menu.framenumber, 'Checked',opt);
% Update Legend menu check:
%
opt = get_param(blk,'AxisLegend');
set(fig_data.menu.axislegend, 'Checked',opt);
% Update Memory menu check:
%
opt = get_param(blk,'Memory');
set(fig_data.menu.memory, 'Checked',opt);
% Update line color menu checks:
%
% Reset all checks for this line in both the options and
% context menus for line styles/colors/markers:
h=[fig_data.menu.linecolor fig_data.menu.linestyle ...
fig_data.menu.linemarker];
hc=get(h,'child');
hc=cat(1,hc{:});
set(hc,'check','off');
% Turn on appropriate menu checks:
for i = 1 : block_data.NChans,
% If item corresponds to a valid index, turn on check-marks
% for that item in both the options and context menus:
% Handle will be empty if menu does not contain user-specified choice
% Update line disable menu checks:
[status, h] = getDialogLineDisable(blk, i);
set(h,'check',status);
% Update line colors menu checks:
[rgb, h] = getDialogLineColor(blk, i);
set(h,'check','on');
% Update line styles menu checks:
[style, h] = getDialogLineStyle(blk, i);
set(h,'check','on');
% Update line markers menu checks:
[marker, h] = getDialogLineMarker(blk, i);
set(h,'check','on');
end
% ---------------------------------------------------------------
function RevertDialogParams(blk)
% Reset all current parameters in block dialog
% These are all the "eval-mode edit box" fields:
block_data = get_param(blk, 'UserData');
names = get_param(blk,'masknames');
styles = get_param(blk,'maskstyles');
% values = get_param(blk,'maskvalues');
pv={};
r = get_param(blk,'maskvariables');
for i=1:length(styles),
[t,r]=strtok(r,'@&');
if (r(1)=='@') & strcmp(styles{i},'edit'), % eval-mode edit box
% Cannot use MaskValues field from the block, since we need
% to access the "old" parameter values and the mask only
% holds the "new" (and apparently erroneous) ones:
val = mat2str(getfield(block_data.params,names{i}));
pv = [pv {names{i},val}];
end
end
set_param(blk,pv{:});
% ---------------------------------------------------------------
function msg = CheckParams(blk, params)
msg = '';
% Check Domain:
% -------------
x = params.Domain;
if (x~=1) & (x~=2) & (x~=3),
msg = 'Domain must be 1 (Time), 2 (Freq), or 3 (User).';
return
end
% Check XLabel:
% -------------
if ~ischar(params.XLabel),
msg = 'X-axis label must be a string.';
return
end
% Check XUnits:
% -------------
x = params.XUnits;
if (x~=1) & (x~=2),
msg = 'X-axis units must be 1 (Hz) or 2 (rad/s).';
return
end
% Check XIncr:
% -------------
if ~isOn(params.InheritXIncr),
x = params.XIncr;
Nx = GetNumberOfElements(x);
if ~isa(x,'double') | issparse(x) | ~isreal(x) | ...
(Nx ~= 1) | (x <= 0),
msg = 'X-axis increment must be a real, double-precision scalar > 0.';
return
end
end
% Check XRange:
% -------------
x = params.XRange;
if (x~=1) & (x~=2) & (x~=3),
msg = 'X-axis range must be 1 [0,Fn], 2 [-Fn,Fn], or 3 [0,Fs].';
return
end
% Check YLabel:
% -------------
if ~ischar(params.YLabel),
msg = 'Y-axis label must be a string.';
return
end
% Check YUnits:
% -------------
x = params.YUnits;
if (x~=1) & (x~=2),
msg = 'YUnits must be 1 (Hz) or 2 (rad/s).';
return
end
% Check horizontal span:
% ----------------------
x = params.HorizSpan;
Nx = GetNumberOfElements(x);
if ~isa(x,'double') | issparse(x) | ~isreal(x) | ...
(Nx ~= 1) | (x ~= floor(x)) | (x <= 0),
msg = 'Horizontal span must be a real, integer-valued scalar > 0.';
return
end
% Check YMin:
% -----------
x = params.YMin;
Nx = GetNumberOfElements(x);
if ~isa(x,'double') | issparse(x) | ~isreal(x) | ...
(Nx ~= 1),
msg = 'Y-minimum must be a real-valued scalar.';
return
end
ymin = x;
% Check YMax:
% -----------
x = params.YMax;
Nx = GetNumberOfElements(x);
if ~isa(x,'double') | issparse(x) | ~isreal(x) | ...
(Nx ~= 1),
msg = 'Y-maximum must be a real-valued scalar.';
return
end
if x<=ymin,
msg = 'Maximum Y-axis limit must be greater than Minimum Y-axis limit.';
return
end
% Check FigPos:
% -------------
x = params.FigPos;
if ~isa(x,'double') | issparse(x) | ~isreal(x) | ...
size(x,1)~= 1 | size(x,2)~=4,
msg = 'Figure position must be a real-valued 1x4 vector.';
return
end
% Check LineColors/Styles/Markers:
% ----------------
x = params.LineColors;
if ~ischar(params.LineColors) | ...
~ischar(params.LineStyles) | ...
~ischar(params.LineMarkers) | ...
~ischar(params.LineDisables),
msg = 'Line Colors, Styles, Markers, and Disables must be strings.';
return
end
% Check AxisGrid:
% Check AxisZoom:
% Check FrameNumber:
% Check AxisLegend:
% Check Memory:
% Check AxisParams:
% Check LineParams:
% -----------------
% (skip checkboxes)
% ---------------------------------------------------------------
function y = relevant_params_changed(params1, params2)
% Remove the "dialog tab" fields, eg, fields that can change
% without affecting any user options:
%
nop={'ScopeProperties','DisplayProperties','AxisProperties','LineProperties'};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -