How do I specify a specific time in my plot?

16 Ansichten (letzte 30 Tage)
Alex Johnson
Alex Johnson am 18 Jul. 2017
Kommentiert: Alex Johnson am 20 Jul. 2017
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 Kommentare
Alan Weiss
Alan Weiss am 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
Alex Johnson
Alex Johnson am 20 Jul. 2017
As you can see above, my plot appears to be almost 'filled in', not just a single line. To my understanding, this is because my script is plotting the temperature against my arbitrary line at every second that the model is ran. So instead of having one line that represents the temperature versus the arbitrary line at second 7200, I have a series of 7200 lines that represent the temperature along the line during the first 7200 seconds the model is ran.
What I am attempting to do is plot the arbitrary line that I drew on my heat transfer model against the temperature along that line at time = (whatever second I specify). I only want my plot to show the temperature at a certain time. For example, I want to add a line or two to my script that can clarify a specific second that my heat transfer model is being ran, then plot just the temperatures at that moment against the line (displaying a plot with a single line), rather then the whole array of lines it is showing now (displaying the 'filled in' plot).
Thanks!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 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 Kommentare
Alan Weiss
Alan Weiss am 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
Alex Johnson
Alex Johnson am 20 Jul. 2017
Perfect thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by