Hi all,
I have temperature data for different depths over time. I'd like to display it with a coloured line plot that shows lines at the different depths filled with the temperature gradients over time (see example below). Attached are variables of depth, time and temperature for 0 meters. Anyone can give some help on how to do this?
Thank you in advance!!

 채택된 답변

Star Strider
Star Strider 2023년 5월 26일

0 개 추천

The patch documentation section on Create Multicolored Line offers one option.
The problem with the data is that the temperature does not vary much with the depth, and then only at the ends —
load('temp0')
load('depth0')
load('time0')
whos
Name Size Bytes Class Attributes ans 1x34 68 char cmdout 1x33 66 char depth0 39577x1 316616 double temp0 39577x1 316616 double time0 39577x1 316648 datetime
temp0s = [min(temp0) max(temp0)]
temp0s = 1×2
13.0732 29.4457
depth0end = depth0(end);
depth0(end) = NaN;
figure
patch(time0, -depth0, temp0, 'EdgeColor','interp')
hold on
scatter(time0(end), -depth0end, 5, temp0(end), 'filled', 's')
hold off
cb = colorbar;
cb.Label.String = 'Temperature (°C)';
colormap(turbo)
xlabel('Time')
ylabel('Depth')
figure
plot3(time0, -[depth0(1:end-1); depth0end], temp0, ':k', 'LineWidth',0.25)
hold on
scatter3(time0, -[depth0(1:end-1); depth0end], temp0, 3.5, temp0, 'filled', 's')
hold off
cb = colorbar;
cb.Label.String = 'Temperature (°C)';
colormap(turbo)
grid on
xlabel('Time')
ylabel('Depth')
zlabel('Temperature')
.

댓글 수: 4

Giulia
Giulia 2023년 5월 29일
cool! Thank you very much!!
This is similar to the plot I came out with using patch with the following code:
x0 = datenum(time0);
y0 = depth0;
z0= temp0;
x0(end+1)=NaN;
y0(end+1)=NaN;
z0(end+1)=NaN;
c0=z0;
figure
patch(x0,y0,c0, Edgecolor = 'interp');
set(gca, 'YDir','reverse');
colorbar;
caxis([14 16]);
datetick
The only thing I am stuck with is how would I add the other sensors of the mooring on the plot, considering the depth and temp variables for each sensor vary in their lengths (e.g. depth and temp of sensor at 5 m is different from depth and temp of sensor at 10 m)? Any suggestions?
Thanks again!
Star Strider
Star Strider 2023년 5월 29일
These are the only data presented.
It would probably be necessary for you to use a loop to plot each each sensor in a separate iteration, and use the hold function to plot them together on the same axes. The sensor data would be put in a matrix, then loop through the rows or colums, depending on how the matrix was organised, or if they were different sizes, in a cell array and then index the cell array in the loop.
Giulia
Giulia 2023년 5월 30일
Got it, will work on it!
Thank you very much for your help!
Star Strider
Star Strider 2023년 5월 30일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 5월 23일

0 개 추천

댓글 수: 2

Giulia
Giulia 2023년 5월 26일
Thanks Walter! I saw those file exchanges but not sure how to apply it to my data (quite new to Matlab).
The syntax of the file exchanges has sin and cos (e.g. y=sin(4*pi*x);z=cos(4*pi*x);), don't know how to use it with my data.
Any idea?
Thank you!
Giulia
Giulia 2023년 5월 26일
x=datenum(time0)
y=depth0
z=temp0
c=z
W=3
p=clinep(x,y,z,c,W);
colorbar
caxis([14 16])
set(gca, 'YDir','reverse');
This came out using this code. How can I add the other sensors? Thank you!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Orange에 대해 자세히 알아보기

질문:

2023년 5월 23일

댓글:

2023년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by