3D plot using time series
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I'm trying to create a 3D graph like the image below. I have attached a reduced data set of my results below. Does anyone know how this would work? 

I've currently tried surf and waterfall but I can't seem to get it working. It a mess but this is kind of what I've been working with
results.
In effect I want each day of the results to be shown on a different "slice"
%Sets Date time format for when table is read
opts = detectImportOptions("results.xlsx","Sheet","Sheet1");
opts = setvartype(opts,"Date","datetime");
opts = setvaropts(opts,"Date",'InputFormat','dd.MM. HH:mm');
results = readtable("results.xlsx",opts);
x = results.Efficiency;
y = results.Power;
% z = results.Date; % HOW DO YOU INCLUDE THIS?
[X,Y] = meshgrid(x,y);
Z = peaks(X,Y);
waterfall(X,Y,Z)
採用された回答
Star Strider
2022 年 4 月 27 日
results = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980365/results.xlsx', 'VariableNamingRule','preserve');
results.Date = datetime(results.Date, 'InputFormat','MM.dd. HH:mm', 'Format','MM.dd. HH:mm')
results = 30×15 table
Date AmbientTemp SkyTemp GlassTemp PVTemp AbsorberTemp Irradiance WindSpeed Power WaterTemp WaterTemp2 Efficiency Hwind Kair Pb
____________ ___________ _______ _________ ______ ____________ __________ _________ ______ _________ __________ __________ ______ _____ _______
01.01. 00:00 300.3 287.26 287.26 286.89 286.5 0 3.7 0 0 289.95 0.19869 19.952 300.3 -1200
01.01. 01:00 299.5 286.11 286.11 285.77 285.41 0 3.2 0 0 289.43 0.19878 18.022 299.5 -1200
01.01. 02:00 298.6 284.82 284.82 284.35 283.85 0 4.8 0 0 288.68 0.19889 24.198 298.6 -1200
01.01. 03:00 299.3 285.82 285.82 285.31 284.77 0 5.5 0 0 289.12 0.19881 26.9 299.3 -1200
01.01. 04:00 298.8 285.11 285.11 284.62 284.1 0 5.1 0 0 288.8 0.19887 25.356 298.8 -1200
01.01. 05:00 299.1 285.54 285.54 285.13 284.71 0 4 0 0 289.09 0.19883 21.11 299.1 -1200
01.01. 06:00 299.1 285.54 285.86 285.47 285.04 12.9 4 2.5645 0 289.25 0.1988 21.11 299.1 -1197.4
01.01. 07:00 300 286.83 293.07 292.88 292.43 259 4.2 51.337 0 292.78 0.19821 21.882 300 -1148.7
01.01. 08:00 300.9 288.12 299.65 299.66 299.18 498 4.2 98.443 0 296 0.19768 21.882 300.9 -1101.6
01.01. 09:00 301.6 289.13 303.02 303.13 302.63 614 4.2 121.2 0 297.65 0.1974 21.882 301.6 -1078.8
01.01. 10:00 302.5 290.42 311.37 311.75 311.19 972 4.4 191.21 0 301.74 0.19672 22.654 302.5 -1008.8
01.01. 11:00 302.8 290.85 306.95 307.17 306.67 732 4.8 144.26 0 299.58 0.19708 24.198 302.8 -1055.7
01.01. 12:00 303 291.14 308.95 309.22 308.71 819 4.6 161.28 0 300.55 0.19692 23.426 303 -1038.7
01.01. 13:00 303.1 291.28 306.04 306.2 305.72 669 4.8 131.9 0 299.12 0.19716 24.198 303.1 -1068.1
01.01. 14:00 303 291.14 304.11 304.2 303.73 582 4.6 114.84 0 298.18 0.19732 23.426 303 -1085.2
01.01. 15:00 302.4 290.28 296.13 295.9 295.41 251 5.9 49.691 0 294.2 0.19797 28.444 302.4 -1150.3
x = results.Efficiency;
y = results.Power;
z = results.AmbientTemp;
xv = linspace(min(x), max(x), numel(x)); % Create Vector For Interpolation
yv = linspace(min(y), max(y), numel(y)); % Create Vector For Interpolation
[X,Y] = ndgrid(xv,yv); % Create Matrices For Interpolation
Z = griddata(x, y, z, X, Y); % Interpolate Matrix
figure
stem3(x, y, z, 'p', 'filled')
grid on
title('Stem Plot')

figure
surfc(X, Y, Z)
grid on
xlabel('Efficiency')
ylabel('Power')
zlabel('Temperature [°C]')
title('Surface Plot')

Experiment with this approach with your actual data.
.
4 件のコメント
Ieuan Price-davies
2022 年 4 月 27 日
That looks great thank you! Is there anyway of having x be the hour of the day and z be the day number within in the year?
Star Strider
2022 年 4 月 27 日
My pleasure!
To do something similar to the original plot in the question, this works —
results = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980365/results.xlsx', 'VariableNamingRule','preserve');
results.Date = datetime(results.Date, 'InputFormat','MM.dd. HH:mm', 'Format','MM.dd. HH:mm')
results = 30×15 table
Date AmbientTemp SkyTemp GlassTemp PVTemp AbsorberTemp Irradiance WindSpeed Power WaterTemp WaterTemp2 Efficiency Hwind Kair Pb
____________ ___________ _______ _________ ______ ____________ __________ _________ ______ _________ __________ __________ ______ _____ _______
01.01. 00:00 300.3 287.26 287.26 286.89 286.5 0 3.7 0 0 289.95 0.19869 19.952 300.3 -1200
01.01. 01:00 299.5 286.11 286.11 285.77 285.41 0 3.2 0 0 289.43 0.19878 18.022 299.5 -1200
01.01. 02:00 298.6 284.82 284.82 284.35 283.85 0 4.8 0 0 288.68 0.19889 24.198 298.6 -1200
01.01. 03:00 299.3 285.82 285.82 285.31 284.77 0 5.5 0 0 289.12 0.19881 26.9 299.3 -1200
01.01. 04:00 298.8 285.11 285.11 284.62 284.1 0 5.1 0 0 288.8 0.19887 25.356 298.8 -1200
01.01. 05:00 299.1 285.54 285.54 285.13 284.71 0 4 0 0 289.09 0.19883 21.11 299.1 -1200
01.01. 06:00 299.1 285.54 285.86 285.47 285.04 12.9 4 2.5645 0 289.25 0.1988 21.11 299.1 -1197.4
01.01. 07:00 300 286.83 293.07 292.88 292.43 259 4.2 51.337 0 292.78 0.19821 21.882 300 -1148.7
01.01. 08:00 300.9 288.12 299.65 299.66 299.18 498 4.2 98.443 0 296 0.19768 21.882 300.9 -1101.6
01.01. 09:00 301.6 289.13 303.02 303.13 302.63 614 4.2 121.2 0 297.65 0.1974 21.882 301.6 -1078.8
01.01. 10:00 302.5 290.42 311.37 311.75 311.19 972 4.4 191.21 0 301.74 0.19672 22.654 302.5 -1008.8
01.01. 11:00 302.8 290.85 306.95 307.17 306.67 732 4.8 144.26 0 299.58 0.19708 24.198 302.8 -1055.7
01.01. 12:00 303 291.14 308.95 309.22 308.71 819 4.6 161.28 0 300.55 0.19692 23.426 303 -1038.7
01.01. 13:00 303.1 291.28 306.04 306.2 305.72 669 4.8 131.9 0 299.12 0.19716 24.198 303.1 -1068.1
01.01. 14:00 303 291.14 304.11 304.2 303.73 582 4.6 114.84 0 298.18 0.19732 23.426 303 -1085.2
01.01. 15:00 302.4 290.28 296.13 295.9 295.41 251 5.9 49.691 0 294.2 0.19797 28.444 302.4 -1150.3
x = hour(results.Date);
y = day(results.Date, 'dayofyear');
z = results.AmbientTemp;
xv = linspace(min(x), max(x), numel(x)); % Create Vector For Interpolation
yv = linspace(min(y), max(y), numel(y)); % Create Vector For Interpolation
[X,Y] = ndgrid(xv,yv); % Create Matrices For Interpolation
Z = griddata(x, y, z, X, Y); % Interpolate Matrix
figure
stem3(x, y, z, 'p', 'filled')
grid on
xlabel('Hour')
ylabel('Day of Year')
zlabel('Temperature [°C]')
title('Stem Plot')

figure
surfc(X, Y, Z)
grid on
xlabel('Hour')
ylabel('Day of Year')
zlabel('Temperature [°C]')
title('Surface Plot')

That should also work with the larger data file.
The original plot has hours on the x-axis, days on the y-axis and temperature on the z-axis, so that is what I am doing here. If you want day on the z-axis, reverse the order of the arguments to the surf function —
figure
surfc(X, Z, Y)
grid on
xlabel('Hour')
zlabel('Day of Year')
ylabel('Temperature [°C]')
title('Surface Plot')

That looks a bit strange to me, however ‘mine is not to reason why ...’
.
Ieuan Price-davies
2022 年 4 月 27 日
Thank you Star Strider that's amazing!
Star Strider
2022 年 4 月 27 日
As always, my pleasure!
To create different surface plots, change the ‘x’ and ‘y’ variables in my code to be the independent variables for the plot, and then use the appropriate ‘z’ vector in the griddata call. The code should be relatively robust to those changes.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
