How do I specify a specific time in my plot?
15 views (last 30 days)
Show older comments
Using the pde toolbox and exported data (p, t, e, and u), I was able to generate a code that produces a plot along an arbitrary line drawn on my model. In this code, I specify two points (The beginning and end points of the line segment), then it plots the line versus the temperature at that point along the line. This code produces a plot of the correct information, but displays a line for every time in the pde model. For example, in my heat transfer model the system was heated for two hours (7200 seconds), the plot produced 7200 lines, one for each second in the model. I need to be able to specify a time in the heating, and plot the line against the temperature at that specific second in time. This is the plot I get with this code and all 7200 lines:

. Here is my code for what I have so far:
point1 = [0, 0]; %Enter XY coordinates of point 1
point2 = [.1, .2]; %Enter XY coordinates of point 2
F = pdeInterpolant(p,t,u);
x = linspace(point1(1), point2(1));
y = linspace(point1(2), point2(2));
uout = evaluate(F,x,y);
line = sqrt(((x-point1(1))).^2 + ((y-point1(2))).^2);
plot(line, uout)
xlabel('Distance')
ylabel('Temperature')
title('Temperattime = second(7200ure Along Arbitrary Line')
2 Comments
Alan Weiss
on 19 Jul 2017
I'm sorry, but I do not understand what you are asking. Can you please describe exactly what you are trying to do, and what kind of information you want?
Also, I added a bit more info to a previous question of yours that might help with your current plotting routine.
Alan Weiss
MATLAB mathematical toolbox documentation
Accepted Answer
Alan Weiss
on 20 Jul 2017
Just one quick thought before I answer: don't use line as a variable name, as it is the name of a built-in function.
It seems that you have a parametrized line along which you are taking a slice:
t = linspace(0.1,0.2);
x = zeros(size(t));
y = t;
uout = evaluate(F,x,y);
plot(t,uout(:,end)) % choose the last time
xlabel('y')
ylabel('Temperature')
title('Temperattime = second(7200ure Along Arbitrary Line')
If, instead, you want to plot the solution at time 3600, use the command
plot(t,uout(:,3600)) % choose time 3600
Alan Weiss
MATLAB mathematical toolbox documentation
3 Comments
Alan Weiss
on 20 Jul 2017
Again, DON'T use line as a variable.
You just need some basic MATLAB plotting.
tt = linspace(0,1);
x = point1(1) + tt*(point1(2) - point1(1));
y = point2(1) + tt*(point2(2) - point2(1));
F = pdeInterpolant(p,t,u);
uout = evaluate(F,x,y);
figure;
s = norm(point2 - point1);
plot(tt*s,uout(:,Moment))
xlabel('Distance')
ylabel('Temperature')
title('Temperattime Along Arbitrary Line')
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (0)
See Also
Categories
Find more on General PDEs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!