本帖最后由 cjfunsw 于 2012-5-24 14:41 编辑
回复 7 # ChaChing 的帖子
ChaChing,你好,我也想用你提供的这个说明。但是我尽管看了Beyondhxf的例子,我还是用不了。请问能提供一个详细的例子,应用这个功能的吗?
或者其他朋友用过这个功能的,能否提供下详细的例子。我是把这个funtion放在m文件开头,然后就从excel里读取数据,再plot图片。然后用addmarkers()的功能。但是总是提示说错误。因为那个narin<1所以出现错误,是怎么回事呢。
我是这么用的,请问哪里错了。
functionho=addmarkers(hi,n)
% ADDMARKERS Add a pre-defined number of markers to a plot instead of
% one at each datapoint which is default in Matlab.
%
% Usage:
% ADDMARKERS(HI) adds 5 markers to the input handle HI, J=1..length(HI)
% ADDMARKERS(HI,N) adds N markers to the input handle HI, J=1..length(HI)
% HO=ADDMARKERS(...) returns the output handle HO for future usage such as
% changing colors, markers, etc.
%
% Hint: use the output handle when adding legends, e.g.
% LEGEND(HO,'legend 1',...,'legend N')
%
% The markers will be added in the following order:
%
% o Circle
% s Square
% d Diamond
% x Cross
% + Plus sign
% * Asterisk
% . Point
% ^ Upward-pointing triangle
% v Downward-pointing triangle
% > Right-pointing triangle
% < Left-pointing triangle
% p Five-pointed star (pentagram)
% h Six-pointed start (hexagram)
%
% By Matthijs Klomp at Saab Automobile AB, 2009-10-11
% E-mail: matthijs.klomp@gm.com
%
if
nargin<2, n=5; end % default number of markers
if
nargin<1, error('Supply an input handle as input argument.'), end
figure(get(get(hi(1),
'parent'),'parent'))% plot in the figure of the handle
subplot(get(hi(1),
'parent')) % plot in the subplot of the handle
hold
on % do not overwrite the current plot
markers = {
'o','s','d','^','v','x','+','*','.','>','<','p','h'};
ho = hi;
% initialize output handle
for
i = 1:length(hi)
x = get(hi(i),
'xdata'); % get the independent variable
y = get(hi(i),
'ydata'); % get the dependent variable data
s = linspace(1,n,length(x));
% sampling independent variable
sn = [1 (2:n-1)+randn(1,n-2)/n n];
% add some noise to avoid overlap
xrs = interp1(s,x,sn,
'nearest'); % downsample to n datapoints
yrs = interp1(s,y,sn,
'nearest'); % downsample to n datapoints
plot(xrs,yrs,
... % Plot the markers
'Marker',markers{i},'LineStyle','None','Color',get(hi(i),'Color'));
ho(i) = plot([0 1],[1 1]*NaN,
... % Create the output handle
'Marker',markers{i},...
'LineStyle',get(hi(i),'Linestyle'),...
'Color',get(hi(i),'Color'));
end
if
nargout==0, clear ho, end
A=xlsread(
'C:\D10RMethod1.xlsx','sheet2','a3:j1953');
x2=plot(A(:,1),A(:,2))
ho=addmarkers(x2,10)
谢谢。
|