Stem Plots

768 views
Skip to first unread message

jonw0224

unread,
Nov 29, 2010, 12:28:37 PM11/29/10
to freemat
For the DSP people out there, this may be useful...

function [A] = stem(X, Y, par)
n = nargin;
para = 'ob';
parb = '-b';
if(n == 1)
Y = linspace(0,size(X,2)-1,size(X,2));
elseif(n == 2)
if(isa(Y, 'char'))
[para, parb] = processLineSpec(Y);
Y = linspace(0,size(X,2)-1,size(X,2));
end
elseif(n == 3)
[para, parb] = processLineSpec(par);
end
plot(Y,X, para);
ylim ([0 max(X)]);
hold on;
for i = 1:size(X,2)
plot([Y(i) Y(i)], [0 X(i)], parb);
end
hold off;
end

function [A,B] = processLineSpec(lis);
n = strfind(lis, '-.');
lis(n+1) = ';';
B =
lis(find(lis~='.'&lis~='o'&lis~='x'&lis~='+'&lis~='*'&lis~='s'&lis~='d'&lis~='v'&lis~='^'&lis~='>'&lis~='<'));
A = lis(find(lis~='-'&lis~=':'&lis~=';'));
n = strfind(B, ';');
B(n) = '.';
end

David Antonio Garcia Campos

unread,
Feb 18, 2013, 11:05:20 PM2/18/13
to fre...@googlegroups.com
Hi Jonathan,
I am using your function which gives me the following error:
23:03:01.837: JIT compile failed:"Call to function size is not JIT-safe" at line 18 of "/Users/dgarciacampos/Desktop/stem.m"

David Antonio Garcia Campos

unread,
Feb 19, 2013, 12:42:26 AM2/19/13
to fre...@googlegroups.com
I was able to fix my problem.
You should always comment your code hehe.
I guess, you are assuming X to be in a certain format.
Thanks anyway, I was able to generate a semi-looking stem graph.
DavidG

behr...@gmail.com

unread,
Apr 7, 2013, 1:46:58 PM4/7/13
to fre...@googlegroups.com
hi,,,i m finding for the stem function where it doesnt exist in the freemat,,,can i know what to do with the code above?


Reply all
Reply to author
Forward
0 new messages