How to display variables on MATLAB plots

Click For Summary
SUMMARY

This discussion focuses on displaying variable values on MATLAB plots, specifically in the context of solving the Hill equation with multiple distance values. The provided MATLAB code generates five plots representing Force versus time for different fixed distances. The key issue addressed is how to annotate each plot with its corresponding distance value. The solution involves using the text function within a loop to label each plot appropriately, ensuring that all five plots are displayed correctly on the same axis.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of the Hill equation and its application in biomechanics
  • Knowledge of ODE (Ordinary Differential Equations) solving in MATLAB
  • Experience with MATLAB plotting functions, including plot and text
NEXT STEPS
  • Explore MATLAB's text function for advanced plotting annotations
  • Learn about MATLAB's ode15s solver for stiff ODEs
  • Investigate the implementation of custom legends in MATLAB plots
  • Research techniques for optimizing MATLAB plot aesthetics and clarity
USEFUL FOR

Researchers, engineers, and students in fields such as biomechanics and computational modeling who are utilizing MATLAB for data visualization and analysis of dynamic systems.

frejatroop
Messages
1
Reaction score
0
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);

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
 
Physics news on Phys.org
Use the
Code:
 [CODE] [ /CODE]
(without the space after the bracket in \CODE to put your code into a code-box.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K