DSP first toolbox for matlab

13 views (last 30 days)
lee
lee on 2 Feb 2012
Commented: Walter Roberson on 6 Sep 2024
Hi...
when i use zvect function to plot the vector in matlab, i receive this error:
>> z = -1 + 6*i
z =
-1.0000 + 6.0000i
>> zvect (z)
??? Error using ==> plot
Error in color/linetype argument
Error in ==> ZVECT at 77
h = plot(real([zFrom;zTo]), imag([zFrom;zTo]), linetype, real(tt), imag(tt),
linetype );
and a plot window pop up in blank means no vector appearance.
plz guide me how to resolve this issue. I am using Matlab 7.12.0 (R2011a)
Thanks
function hv = zvect(zFrom, zTo, arg3, arg4)
%ZVECT Plot vectors in complex z-plane from zFrom to zTo
%
% usage: HV = zvect(zFrom, <zTo>, <LTYPE>, <SCALE>)
%
% Z: is a vector of compplex numbers; each one will be
% displayed as an arrow emanating from the origin.
% LTYPE: string containing any valid line type (see PLOT)
% SCALE: controls size of arrowhead (default = 1.0)
% (order of LTYPE and SCALE args doesn't matter)
% HV: output handle from graphics of vector plot
%
% ** With only one input vector: zvect(Z)
% displays Z as arrows emanating from the origin.
% ** If either zFrom or zTo is a scalar all vectors will
% start or end at that point.
%
% See also ZCAT, PLOT, COMPASS, ROSE, FEATHER, QUIVER.
% based on the MATLAB toolbox function COMPASS
zFrom = zFrom(:).';
scale = 1.0;
vv = version;
if( vv(1)=='5')
linetype = 'b-';
else
linetype = 'w:-'; %<--- WHITE is NOT good in v5
end
if( nargin==1 )
zTo = zFrom; zFrom = 0*zTo;
elseif( nargin == 2 )
if( isstr(zTo) )
linetype = zTo; zTo = zFrom; zFrom = 0*zTo;
elseif( isempty(zTo) )
zTo = zFrom; zFrom = 0*zTo;
elseif( length(zTo)==1 )
zTo = zTo*ones(size(zFrom));
end
elseif( nargin==3 )
if( isstr(arg3) ), linetype = arg3;
else, scale = arg3;
end
elseif( nargin == 4 )
if( isstr(arg3) ), linetype = arg3; scale = arg4;
else, scale = arg3; linetype = arg4;
end
end
zTo = zTo(:).';
jkl = find( ~isnan(zTo-zFrom) );
if( length(jkl)==0 ), error('cannot plot NaNs'), end
zTo = zTo(jkl);
zFrom = zFrom(jkl);
if( length(zFrom)==1 )
zFrom = zFrom*ones(size(zTo));
elseif( length(zTo)==1 )
zTo = zTo*ones(size(zFrom));
end
if length(zFrom) ~= length(zTo)
error('ZVECT: zFrom and zTo must be same length.');
end
tt = [zFrom,zTo];
[zmx,jkl] = max(abs(tt));
figsize = max(abs(tt-tt(jkl)));
arrow = scale*([-1; 0; -1] + sqrt(-1)*[1/4; 0; -1/4]);
dz = zTo - zFrom;
dzm = abs(dz);
zmax = max(dzm);
zscale = mean([zmax,figsize]);
scz = 0.11 + 0.77*(dzm/zscale - 1).^6;
tt = [ ones(3,1)*(zTo) + arrow*(scz.*dz) ];
next = lower(get(gca,'NextPlot')); %--Ver 4.1
isholdon = ishold; %--Ver 4.1
h = plot(real([zFrom;zTo]), imag([zFrom;zTo]), linetype,...
real(tt), imag(tt), linetype );
num_zzz = length(zFrom);
for kk = 1:num_zzz
kolor = get(h(kk),'color');
set(h(kk+num_zzz), 'color',kolor);
end
axis('equal'); %--Ver 4.1
if ~isholdon; %--Ver 4.1
set(gca,'NextPlot',next); %--Ver 4.1
end; %--Ver 4.1
if nargout > 0
hv = h;
end

Accepted Answer

Walter Roberson
Walter Roberson on 3 Feb 2012
Replace the 'w:-' with 'w:'
  3 Comments
Marshall
Marshall on 5 Sep 2024
Edited: Marshall on 5 Sep 2024
I'm having the same issue, I made the change to 'w:' and now no errors pop up but still nothing gets plotted.
Walter Roberson
Walter Roberson on 6 Sep 2024
If you run on MATLAB Online or MATLAB Answers, then the default background color for plotting is white, and using a white marker does not show up against a white background. You see results if you change it to something like 'r:'

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!