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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by