www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@breakpointeditor/pPlotModel.m
function pPlotModel(obj) % breakpointeditor.pPlotModel Private function. % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. SFData = obj.SFData; if isempty(SFData) return end d = obj.userdata; % ensure that we get the variables the right way round. vars = SFData.VarPtrs; % this will be one or two xregpointers norm = obj.normptr; normvar = norm.getinports; % this will be a single xregpointer if isempty(SFData.YData) || normvar==vars(1) Xdata = SFData.XData; Ydata = SFData.YData; else % reverse inputs Xdata = SFData.YData; Ydata = SFData.XData; end Zdata = SFData.MData; Num = obj.userdata.LineCount; % Now use the supplied X,Y & M data S = size(Xdata); delete(d.ModelLines); d.ModelLines = gobjects(0); if isempty(Ydata) % only one input to worry about temp = [Xdata(:) Zdata(:)]; temp = sortrows(temp); X = temp(:,1); % Plotting coordinates Y = temp(:,2); if obj.userdata.ModelFlag == 2 % calculate the second derivative (roughly), to get the model curvature h = mean(unique(diff(X))); % Need to divide by dx^2 to get the actual second derivative approx. Y = diff(Y,2)/h^2; X = X(2:end-1); end if S(1) == 1 || S(2) == 1 % Xdata is a vector, so we can just plot it. % Since we only have a vector we can't show many lines (What to sweep through?) and so we'll need to kill off % one of the uimenus. d.ModelLines = line(X,Y,... 'Color','b',... 'UIContextMenu',d.ModelMenu,... 'Parent',obj.LineAxes); else % Xdata is a matrix, we'll need to plot a 'cloud' of points. d.ModelLines = line(X,Y,... 'Color','b',... 'Parent',obj.LineAxes,... 'LineStyle','none',... 'Marker','.',... 'MarkerSize',12); end Mx = max(Y(:)); % We need to rescale axes so to something sensible, Mn = min(Y(:)); % so keep a record of the max and mins of the bluelines else X = unique(Xdata(:)); Y = unique(Ydata(:)); if isequal(X,(Xdata(1,:))') % rows of Z correspond to different values of y Zdata = Zdata'; % Transpose so that columns correspond to changing y values. end L = length(Y); Index = round(linspace(1,L,Num+2)); % Index of Y values to display. Index = Index(2:end-1); if obj.userdata.ModelFlag == 2 % calculate the second derivative (roughly), to get the model curvature h = mean(unique(diff(X))); Zdata = diff(Zdata,2,1)/h^2; X = X(2:end-1); end Mx = []; Mn = []; for i = 1:Num d.ModelLines(i) = line(X,Zdata(:,Index(i)),... 'Color','b',... 'Parent',obj.LineAxes,... 'UIContextMenu',d.ModelMenu); Mx = [Mx;max(Zdata(:,Index(i)))]; % We'll need to rescale axes to something sensible, Mn = [Mn;min(Zdata(:,Index(i)))]; % so keep a record of the max and mins of the bluelines end end mx = max(Mx); mn = min(Mn); if mx == mn if mx ~= 0 mx = 1.1*mx; mn = .9*mn; else mx = 1; mn = -1; end end yrange = sort([(9*mn-mx)/10 , (11*mx-mn)/10 ]); set(obj.LineAxes,'YLim',yrange); % new axis limits % set the vertical lines to fill the Y-range of the axes set(d.Lines,'YData',yrange); for i=1:length(d.MissingLines) set(d.MissingLines{i},'YData',yrange); end obj.userdata = d;