plotlogx.m (1740B)
1 function []=plotlogx(x,y,sym,axlabel,fsize,color,shiftx,shifty); 2 % function []=plotlogx(x,y,sym,axlabel); 3 % 4 % Plots y vs x with x on a log scale (natural log). 5 % 6 % sym is a symbols argument: if a string, then just pass it 7 % along to plot. If a vector, then use as plotname. 8 % 9 % axlabel is the string to use to label the y axis. 10 11 if exist('sym')~=1; sym='-';end; 12 if exist('axlabel')~=1; axlabel=[];end; 13 if exist('fsize')~=1; fsize=8; end; 14 if exist('color')~=1; color=[0 .4 0]; end; 15 16 if size(sym,1)==1; 17 plot(log(x),y,sym); 18 else; 19 if size(sym,2)<4; % If you send 3 letter codes, just those, else sym and name 20 plotname(log(x),y,sym,fsize,color); 21 else; 22 plotnamesym(log(x),y,sym,fsize,color,shiftx,shifty); 23 end; 24 end; 25 26 % Now fix the log scale for the y axis. 27 %val=[1000 2000 4000 8000 16000 32000]'; 28 %labs=strmat('1000 2000 4000 8000 16000 32000'); 29 if isempty(axlabel); 30 curlabs=get(gca,'XTickLabel'); 31 newnum=exp(str2num(curlabs)); 32 newlabs=num2str(newnum,'%6.0f'); 33 if any(delta(str2num(newlabs))==0); 34 % if size(newlabs,2)==1; % Add another significant digit 35 newlabs=num2str(newnum,'%6.1f'); 36 set(gca,'XTick',log(1/10*round(newnum*10))); 37 else; 38 set(gca,'XTick',log(round(newnum))); 39 end; 40 set(gca,'XTickLabel',newlabs); 41 % Old error: set(gca,'YTick',str2num(curlabs)); %But there is rounding!!!! 42 else; 43 if size(axlabel,1)==1; labs=strmat(axlabel); else; labs=axlabel; end; 44 logval=log(str2num(axlabel)); 45 set(gca,'XTick',logval); 46 set(gca,'XTickLabel',labs); 47 % Also adjust XLim in case one of labels is outside the range: 48 curlim=get(gca,'XLim'); 49 curlim(1)=min([curlim(1) min(logval)]'); 50 curlim(2)=max([curlim(2) max(logval)]'); 51 set(gca,'XLim',curlim); 52 end;