简体   繁体   中英

Plotting of a expotential curve between an interval in MATLAB

I would like to plot an expotential curve between an interval based on a different multipler for each interval.

I have tried this:

%Plotting of h curve
function PlotQ(Time,h)
    for i=2:size(Time,1)
        for t=Time(i-1):0.1:Time(i)
            plot([Time(i-1), Time(i)],exp(-h(i)*t))
            hold on; 
        end
    end
    ymax = max();
    xlim([1 max(Time)]);
    ylim([-0.5 ymax+0.5]);
    xlabel('Time')
    ylabel('Rate')
end

The curve comes out like this:

在此处输入图片说明

Not sure what I am doing wrong.. Need some guidance..

New Edit:

T =[0;0.569444444444444;1.06666666666667;2.08611111111111;3.09722222222222;4.11111111111111;5.12500000000000;7.16111111111111;10.2000000000000;20.3444444444444;30.4944444444444];
%Plotting of h and Q
h = [0;0.0187;0.0194;0.0198;0.0215;0.0225;0.0241;0.0316;0.0379;0.0437;0.0452];
PlotQ(Time,h)

If I understood correctly, You are looking for something like this.

%Plotting of h curve
function PlotQ(Time,h)
    for i=2:size(Time,1)
        tVector=Time(i-1):0.1:Time(i);
        sizetVector=length(tVector);
        for t=2:sizetVector
            plot([tVector(t-1), tVector(t)],[exp(-h(i)*tVector(t-1)),exp(-h(i)*tVector(t))]);
            hold on
        end    
    end
    ymax = max();
    xlim([1 max(Time)]);
    ylim([-0.5 ymax+0.5]);
    xlabel('Time')
    ylabel('Rate')
end

I think, this is what you want:

function PlotQ(Time,h)
    % Parameters
    res = 0.1;
    n = numel(h);
    % Pre-allocate
    y = cell(1,n);    
    t = cell(1,n);
    % Calculate
    for ii=2:n
        t{ii} = Time(ii-1):res:Time(ii);
        y{ii} = exp(-h(ii)*t{ii});
    end
    % Plot
    t_ = [t{:}];   
    y_ = [y{:}];
    figure;    
    plot(t_,y_);
    axis([1 max(t_) -0.5 max(y_)+0.5]);
    xlabel('Time');   
    ylabel('Rate');
end

It gives the following plot:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM