필터 지우기
필터 지우기

how to plot multiple decaying exponentials in one plot.

조회 수: 3 (최근 30일)
Romio
Romio 2019년 5월 20일
댓글: Alex Mcaulley 2019년 5월 20일
I would like to plot multiple decaying exponentials with different parameters (time, decay, peak). I was able to create this code to plot only one decaying exp. at t=20
clc,clear,close all
time = [20];
peak = [5];
decay = [2];
t = 1:100;
X = zeros(length(t),1);
for j = 1:length(t)
for i = 1:length(time)
if t(j) > time(i)
X(j) = peak(i)*exp(-(t(j)-time(i))/decay(i));
end
end
end
plot(t,X)
now say I have arrays of parameters like this
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
and I want to plot three consecutive decaying exponentials using each element of these parameters. Any thoughts on how to go about it?
Thanks,

답변 (1개)

Alex Mcaulley
Alex Mcaulley 2019년 5월 20일
Here two options:
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
% Symbolic toolbox needed
figure
syms t
X = peak.*exp(-(t-time)./decay);
fplot(X,[1,100])
%Anonymous functions
figure
t = 1:100;
X = @(t) peak.*exp(-(t-time)./decay);
plot(t,cell2mat(arrayfun(X,1:100,'UniformOutput',false)'))
  댓글 수: 2
Romio
Romio 2019년 5월 20일
Thanks. But they do not correspond to the parameters (e.g. they should be at 20 50 80 with the spcified amplitudes/decay). Also I need them in a loop fasion so that I can use them as an input to dfferent program.
Alex Mcaulley
Alex Mcaulley 2019년 5월 20일
Why do you want to do it with loops? It is inefficient, but you can do it easily adding another loop (from 1 to size(time)).
By the way, following my previous code, to shift the exponentials to the desired position:
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
t = cell2mat(arrayfun(@linspace,time,100*ones(size(time)),'UniformOutput',false)');
X = @(t) peak.*exp(-(t)./decay);
plot(t',cell2mat(arrayfun(X,linspace(0,100),'UniformOutput',false)'))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by