How to display variables on MATLAB plots

In summary, the conversation discusses using MATLAB to generate 5 plots of Force versus time for the Hill equation with 5 different values of distance x. The goal is to interpret the relationship between x and F(t) and determine which plot represents which value of x. The code provided includes the Hill model equation with a fixed variable for distance and a pre-calculated activation function. The attempt at a solution involved using a for loop to plot each of the 5 values of x and labeling the plots with the corresponding distance value, but only one plot was generated instead of 5.
  • #1
frejatroop
1
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
  • #2
Use the
Code:
 [CODE] [ /CODE]
(without the space after the bracket in \CODE to put your code into a code-box.
 

FAQ: How to display variables on MATLAB plots

How do I display a single variable on a MATLAB plot?

To display a single variable on a MATLAB plot, you can use the plot function. Simply pass in the variable as an argument, and the plot will be automatically generated. For example: plot(x) will plot the variable x on the y-axis against its index on the x-axis.

Can I display multiple variables on the same MATLAB plot?

Yes, you can display multiple variables on the same MATLAB plot by passing in multiple arguments to the plot function. For example: plot(x, y, z) will plot the variables x, y, and z on the same plot with their respective indices on the x-axis.

How do I customize the appearance of a MATLAB plot?

To customize the appearance of a MATLAB plot, you can use various functions such as title, xlabel, ylabel, legend, and grid. These functions allow you to add a title and axis labels, create a legend, and add grid lines to your plot.

How can I save a MATLAB plot as an image file?

You can save a MATLAB plot as an image file by using the saveas function. Simply pass in the plot and the desired file format as arguments, for example: saveas(fig, 'myplot.png') to save the plot as a PNG file.

Can I display variables on different types of MATLAB plots?

Yes, there are various types of plots available in MATLAB such as scatter plots, bar graphs, histograms, and more. You can use functions like scatter, bar, and histogram to display variables on these different types of plots. Simply pass in the variables as arguments to the respective plot functions.

Similar threads

Replies
6
Views
2K
Replies
8
Views
843
Replies
6
Views
4K
Replies
4
Views
3K
Replies
3
Views
1K
Replies
2
Views
14K
Back
Top