Display 2D Data in a 3D plot

1 回表示 (過去 30 日間)
Remo
Remo 2023 年 6 月 20 日
コメント済み: Remo 2023 年 6 月 22 日
For a task i need to make 3D-Plot of following Data and compare them in one plot.
Emissions transport (28x1)
Emissions Flug-Schiffsverkehr (28x1)
Years (28x1)
so in one plot ( x = years, y = Data1, z=x) %% I made z=x because i dont know what other data i should use.
other plot ( x = years, y = Data2, z=x)
Has anyone an idea so it makes sense to do this in 3d.
here is my code as far
excel = readmatrix("je-d-02.03.02.03.xlsx")
x = excel(12:39,2)
y = excel(42:69,6)
z = x
y(isnan(y))=0;
[Ux,iax,ixx] = unique(x)
[Uy,iay,ixy] = unique(y)
N = 25 % einstellen
xv = linspace(min(x),max(x),N)
yv = linspace(min(y),max(y),N)
[Xm,Ym] = ndgrid(xv,yv)
Zm = griddata(x, y, z, Xm, Ym)
figure
surfc(Xm, Ym, Zm)
grid on
hold on
xlabel('Jahre')
ylabel('Transport in Mio t')
zlabel('Jahre')
title('3D-Grafik: Gegenüberstellung der Emissionen Transport & Internationaler Luft- und Schiffsverkehr')
legend('Jahre','Transport','Jahre')
%% Zweiter Plot
y2 = excel(72:99,16)
y2(isnan(y2))=0;
[Uy2,iay2,ixy2] = unique(y2)
y2v = linspace(min(y2),max(y2),N)
[Xm,Ym2] = ndgrid(xv,y2v)
Zm2 = griddata(x, y2, z, Xm, Ym2)
surfc(Xm, Ym2, Zm)
  2 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 6 月 21 日
why don't you simply 2D plot the data (Emissions transport (28x1), Emissions Flug-Schiffsverkehr (28x1)) vs. the years ?
Remo
Remo 2023 年 6 月 21 日
Yes would love to :D Im a student and this is a task i cant refuse to do.
I think i will try to do one data on 2 axes like y and z and then the years on x.
I hope i get a 2d plot with a 3D look so my prof is happy.

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

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 6 月 21 日
i believe that should be sufficient for what we need
pay attention to your row and column indexes when you import data (here with readmatrix) as this does not reflect how it's done inside the excel spreadsheet !
here a code with more robust data management
also you could have different x1 and x2 range (years) , that would not be a problem for the plot itself
data = readmatrix("je-d-02.03.02.03.xlsx");
% important NB : data will be read after the first 11 header lines so there is a
% shift in row index vs when you look at the excel file directly
row_shift = 11;
%% Erster Plot
% data 1 : Transport (ohne internationalen Flugverkehr)
rows = (42:69)-row_shift; % remember NB above !!
col = 2;
x1 = data(rows,col); % years (x axis)
y1 = data(rows,col+4); % CO2-Äquivalente 2)Total (y axis)
%% Zweiter Plot
% data 2 : TInternationaler Flug- und Schiffsverkehr )
rows = (72:99)-row_shift; % remember NB above !!
col = 12;
x2 = data(rows,col); % years (x axis)
y2 = data(rows,col+4); % CO2-Äquivalente 2)Total (y axis)
plot(x1,y1,x2,y2);
xlabel('Jahre')
ylabel('CO2-Äquivalente Mio. t')
title('2D-Grafik: Gegenüberstellung der Emissionen Transport & Internationaler Luft- und Schiffsverkehr')
legend('Transport','Internationaler Flug- und Schiffsverkehr')
  1 件のコメント
Remo
Remo 2023 年 6 月 22 日
Thank you for youre effort. I didnt solve the problem but i found a solution. I used the bar3 command so a lot of the code fall away The Result is a 2D Data plot shown in 3D bars and i hope my prof accepts this.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by