⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xferplot.m

📁 MATLAB的FPGA数字信号处理程序 类似于DSP的C语言 简称SG
💻 M
📖 第 1 页 / 共 5 页
字号:
% ---------------------------------------------------------------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;endblock_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/contexthclrs   = cat(2,hclrs{:});            % matrix of handles: colors x [options context]menuRGB = get(hclrs(:,1),'UserData'); % cell array of RGB vectors just for options menuh = [];  % in case no match is foundfor 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;	endend% ---------------------------------------------------------------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 blackif 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 emptyblock_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 specend% ---------------------------------------------------------------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 specsuser_cspec = get_pipestr(pipestr,lineNum,1);  % cspec for line lineNumrgb = mapCSpecToRGB(blk, user_cspec);         % find RGB representation - empty if no matchif nargout>1,	h = getColorMenuHandlesFromRGB(blk, lineNum, rgb); % get handles - may be emptyend% ---------------------------------------------------------------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 specsstyle = get_pipestr(pipestr,lineNum,1);  % style for line lineNum% Map from user-specified style to actual style string:if isempty(style),	style='-';endh = getStyleMenuHandlesFromStyle(blk, lineNum, style); % get handles - may be empty% ---------------------------------------------------------------function y = anyStemMarkers(blk)% Determine if any lines have a Stem marker selectedblock_data = get_param(blk,'UserData');nchans = block_data.NChans;pipestr = get_param(blk,'LineMarkers');   % get all user-specified marker specsy = 0;  % assume no stem markers selectedfor lineNum=1:nchans,	marker = get_pipestr(pipestr, lineNum,1);	y = strcmp(marker,'stem');	if y, return; endend% ---------------------------------------------------------------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 specsmarker = get_pipestr(pipestr,lineNum,1);  % marker for line lineNum% Map from user-specified marker to actual style string:if isempty(marker),	marker='None';endh = 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 specsdisable = get_pipestr(pipestr,lineNum,1);  % disable for line lineNum% Map from user-specified disable to actual disable string:if isempty(disable),	disable='on';endh = getDisableMenuHandles(blk, lineNum);% ---------------------------------------------------------------function SetMenuChecks(blk)% Called only from first_update to preset menu checks% blk: masked subsystem blockblock_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}];	endendset_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).';	returnend% Check XLabel:% -------------if ~ischar(params.XLabel),	msg = 'X-axis label must be a string.';	returnend% Check XUnits:% -------------x = params.XUnits;if (x~=1) & (x~=2),	msg = 'X-axis units must be 1 (Hz) or 2 (rad/s).';	returnend% 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	endend% 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].';	returnend% Check YLabel:% -------------if ~ischar(params.YLabel),	msg = 'Y-axis label must be a string.';	returnend% Check YUnits:% -------------x = params.YUnits;if (x~=1) & (x~=2),	msg = 'YUnits must be 1 (Hz) or 2 (rad/s).';	returnend% 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.';	returnend% 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.';	returnendymin = 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.';	returnendif x<=ymin,	msg = 'Maximum Y-axis limit must be greater than Minimum Y-axis limit.';	returnend% 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.';	returnend% 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.';	returnend% 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'};params1 = rmfield(params1,nop);params2 = rmfield(params2,nop);y = ~isequal(params1,params2);% ---------------------------------------------------------------function DialogApply(params,block_name)% Called from MaskInitialization command via:%   sdspfscope2([],[],[],'DialogApply',params);% Updates block_data% In case of call from an internal method (not a callback)% For example, SetAndApply calls us directly, and gcb might% not be correct...if nargin<2,	block_name = gcb;endblock_data = get_param(block_name, 'UserData');if isempty(block_data),	return;  % System has not run yetend% Check dialog parameters:% ------------------------msg = CheckParams(block_name, params);if ~isempty(msg),	% Invalid parameters	errordlg(msg,'Frame Scope Dialog Error','modal');	RevertDialogParams(block_name);	returnend% On start-up, no params field exists% Set params, and skip any further processingif ~isfield(block_data,'params'),	block_data.params = params;	set_param(block_name, 'UserData', block_data);	return;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -