How to plot the mean value of X corresponding to each Y value?

10 ビュー (過去 30 日間)
Alejandra Uguet de Resayre
Alejandra Uguet de Resayre 2023 年 1 月 11 日
コメント済み: Star Strider 2023 年 1 月 13 日
Hello!
I want to plot a vertical profile of temperature (so Y-axis is depth (m) and X-axis is temperature (ºC)). Because I have many measurements for each depth, what I get is a profile made of a cloud of points:
However, I would like to get a linear profile, so I guess I would need to plot each X mean value for each Y, right?
Could someone please help me on that?
Thanks a lot!
  3 件のコメント
Alejandra Uguet de Resayre
Alejandra Uguet de Resayre 2023 年 1 月 11 日
It doesn't let me attach the mat file because it is too big (more than 5MB).
What I mean is that from that cloud of points I want to get something like this instead, like a single line thing, so I guess that's the mean value of X for each Y.
Thank you for answering!! <3 <3 <3
Star Strider
Star Strider 2023 年 1 月 11 日
@Alejandra Uguet de Resayre — Please see my latest Comment to my Answer. It produces the result matching the plot you posted.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2023 年 1 月 11 日
I am not certain what you want.
Perhaps something like this —
x = ones(9,1)*linspace(13, 19, 50); % Create Data
y = 8E+2*(1-exp(-5*(x-13)))-1E+3 + randn(9,size(x,2))*75; % Create Data
T = x(:); % Temperature (Assume Column Vector)
D = y(:); % Depth (Assume Column Vector)
NBins = 14; % Change This To Change Temperature Resolution
[N,Edges,Dpthv] = histcounts(D, NBins);
Ctrs = Edges(1:end-1) + mean(diff(Edges)); % Depth Centers
% Tvct = linspace(min(T), max(T), NBins);
TempMean = accumarray(Dpthv, T, [], @mean) % Calculate Mean Temperature At Each Depth
TempMean = 14×1
13.0000 13.0000 13.0000 13.0000 13.1224 13.1224 13.1224 13.1837 13.6234 15.5923
figure
plot(T, D, '.r', 'DisplayName','Data')
hold on
plot(TempMean, Ctrs, '.-b', 'DisplayName','Mean Temperature')
hold off
grid
xlabel('Temperature (°C)')
ylabel ('Depth (m)')
legend('Location','best')
The blue line plots depth as a function of the mean temperature.
.
  9 件のコメント
Alejandra Uguet de Resayre
Alejandra Uguet de Resayre 2023 年 1 月 13 日
You all are right :) Thank you both for your time invested, it helped me so much.
Star Strider
Star Strider 2023 年 1 月 13 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2023 年 1 月 11 日
hello
yes i'm coming late in the show... nevertheles I am here !!
just for the fun and FYI
your data could be decimated up to factor 100 without loss of quality I think
without decimation :
with decimation factor 50
code
load('matlab.mat');
temp = candec18tCopy.theta;
depth = -candec18tCopy.dep;
% remove nan's
idx = isnan(temp);
temp(idx) = [];
depth(idx) = [];
% sort
[temp,id] = sort(temp,'ascend');
depth = depth(id);
% unique
[temp,IA,IC] = unique(temp);
depth = depth(IA);
% decimation
decim_fact = 50; % test with 1 to 100
ind = 1:decim_fact:numel(depth);
temp = temp(ind);
depth = depth(ind);
% remove data below 13.25
ind = (temp<13.25);
temp(ind) = [];
depth(ind) = [];
depth_s = smoothdata(depth,'movmedian',round(10000/decim_fact));
plot(temp,depth,'*r',temp,depth_s,'-b')
  2 件のコメント
Alejandra Uguet de Resayre
Alejandra Uguet de Resayre 2023 年 1 月 11 日
yes yes yes!! thank you soooo much Mathieu
Mathieu NOE
Mathieu NOE 2023 年 1 月 12 日
My pleasure !
Glad it worked

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by