1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to display variables on MATLAB plots

  1. Nov 1, 2014 #1
    The question gives the code for MATLAB to solve Hill equation with 5 different values of distance x, which will generate 5 plots on same axis. But the plots will be Force versus time. The question ask you to interpret the relationship between X and F(t).

    How do I know this plot represents which value of x?
    2. Given code with fixed variable for Hill model equation Bolded line is the distance which I'd like to show it on plots

    clear
    global kpe kse b xstar x delay A tv
    kpe = 75; % spring constant of parallel element, g/cm
    kse = 136; % spring constant of series element, g/cm
    b = 50; % viscosity of parallel dashpot, (g*s)/cm
    delay = 0.1; % delay before stimulation, s
    xv = [1 1.5 2 2.5 3.0]; %fixed length in cm
    xstar = 1; % resting length, cm
    tspan = [0 .5]; % time span, s

    % pre-calculate the activation function A(t)
    dtv = 0.0001;
    tv = [tspan(1):dtv:tspan(2)];
    A = 1*(tv>delay).*(48144*exp(-(tv-delay)/0.0326) - 45845*exp(-(tv-delay)/0.034));

    cvect ='bgrck';
    figure
    hold

    AND code for ODE
    function dFdt = hill_isometric_rhs(t,F)
    global kpe kse b xstar x delay A tv

    % scaling function for A(t) as a function of length
    s = (x>0.5*xstar)*(x<1.5*xstar)*(cos(pi*(x-xstar)));

    % instead of calculating A(t), use precalculated version
    %Aloc = 1*(t>delay)*(48144*exp(-(t-delay)/0.0326) - 45845*exp(-(t-delay)/0.034));
    % imin = index of nearest match to current value of t
    % using a fine grid, no need to interpolate
    [tmin,imin]=min(abs(tv-t));
    Aloc = A(imin);

    dFdt = kse/b*(kpe*(x-xstar)*(x>xstar) - (1+kpe/kse)*F + Aloc*s);

    3. The attempt at a solution
    I tried using
    for i=1:length(xv)
    x = xv(i);
    F0 = (x>xstar)*kpe*(x-xstar)/(1+kpe/kse);
    [t,F]=ode15s('hill_isometric_rhs',tspan,F0);
    plot(t,F,cvect(i))
    text(t, F, ['Distance is: ', num2str(x)]);

    Q = quotation(rand);
    if isempty(Q); error('Quotation server filesystem problems')
    else sprintf('%s',Q), end


    end

    But it only shows one line, while without the italic part, 5 plots are generated normally
     
  2. jcsd
  3. Nov 2, 2014 #2

    Maylis

    User Avatar
    Gold Member

    Use the
    Code (Text):
     [CODE] [ /CODE]
    (without the space after the bracket in \CODE to put your code into a code-box.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: How to display variables on MATLAB plots
  1. Matlab, plot (Replies: 5)

  2. Matlab plots (Replies: 1)

Loading...