I want to break down my 3d graph into 2d graphs.

1 view (last 30 days)
Hello Everyone,
I have a 3D derived graph. In this 3D graph, I want to obtain graphs such as x-z graph where y=constant and y-z graph where x=constant value. Additonal I want to take the derivatives of these graphs.
I leave the code below.
Thank you for your support.
T=273:1:420; %axisy
% x=0:0.1:10;
x = linspace(0, 0.35, 22);
Txm=1:1:148;
Txn=1.21:1:148.21;
Txmn=Txn-Txm; % X=0.21 (axis x measured first value)
Txk=1:1:148;
Txmk=Txk-Txm; % X=0; (axis x measured second value)
%lamda11=0.002547*(T.^2)+-0.01608*T+ 7162 ; %axis z(y) function
%lamda22=0.004723*(T.^2) +0.07403*T + 6962 ; %axis z(y) function
lamda__11= 0.00472 .*(T.^2)+0.0740 .*T+8.623e+03 %lamda %Eg(0)
lamda__11 = 1×148
1.0e+03 * 8.9950 8.9976 9.0003 9.0030 9.0057 9.0084 9.0111 9.0138 9.0165 9.0192 9.0220 9.0247 9.0275 9.0302 9.0330 9.0358 9.0386 9.0414 9.0442 9.0471 9.0499 9.0527 9.0556 9.0585 9.0613 9.0642 9.0671 9.0700 9.0729 9.0758
lamda__44= 0.00255 .*(T.^2)-0.0161 .*T+8.8230e+3 %lamda %Eg(0.21)
lamda__44 = 1×148
1.0e+03 * 9.0087 9.0100 9.0114 9.0128 9.0142 9.0156 9.0170 9.0184 9.0198 9.0212 9.0227 9.0241 9.0255 9.0270 9.0284 9.0299 9.0313 9.0328 9.0343 9.0357 9.0372 9.0387 9.0402 9.0417 9.0432 9.0447 9.0462 9.0477 9.0492 9.0507
cmtx11 = [0.00255 -0.0161 8.8230e+3; 0.00472 0.0740 8.623e+03];
cmtx = cmtx11 ; % Parameter Matrix
for k = 1:size(cmtx,2)
DM = [0 1; 0.21 1]; % Design Matrix
Bx(:,k) = DM \ cmtx(:,k); % Linear Regression For Each Coefficient
Ck(:,k) = DM * Bx(:,k); % Check Results
end
% format longG
% Bx
% Ck
format shortE
lambdafcn = @(T,x) [x 1]*Bx(:,1).*(T.^2) + [x 1]*Bx(:,2).*T + [x 1]*Bx(:,3); % 'lambda' Function Incorporating Linear Regression Parameters For Each Coefficient
[xm,Tm] = ndgrid(x, T); % Create Matrices From Vectors
xv = xm(:);
Tv = Tm(:);
for k = 1:numel(xm)
lambdav(k,:) = lambdafcn(Tv(k),xv(k)); % Create Vector Of 'lambda' Values For 'scatteredInterpolant'
end
Fz = scatteredInterpolant(Tm(:), xm(:), lambdav); % Create Interpolation Function
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
x_07 = 0.07+zeros(size(T(:))); % Define 'x' Vector
Line_07 = Fz(T(:), x_07); % Interpolate Line
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)

Accepted Answer

Star Strider
Star Strider on 5 Jan 2024
The easiest way to do this is with the view function.
Use ‘view(90,0)’ for the ‘x-z’ view, and ‘view(0,0)’ for the ‘y-z’ view.
I added both of those at the end of the original code —
T=273:1:420; %axisy
% x=0:0.1:10;
x = linspace(0, 0.35, 22);
Txm=1:1:148;
Txn=1.21:1:148.21;
Txmn=Txn-Txm; % X=0.21 (axis x measured first value)
Txk=1:1:148;
Txmk=Txk-Txm; % X=0; (axis x measured second value)
%lamda11=0.002547*(T.^2)+-0.01608*T+ 7162 ; %axis z(y) function
%lamda22=0.004723*(T.^2) +0.07403*T + 6962 ; %axis z(y) function
lamda__11= 0.00472 .*(T.^2)+0.0740 .*T+8.623e+03 %lamda %Eg(0)
lamda__11 = 1×148
1.0e+03 * 8.9950 8.9976 9.0003 9.0030 9.0057 9.0084 9.0111 9.0138 9.0165 9.0192 9.0220 9.0247 9.0275 9.0302 9.0330 9.0358 9.0386 9.0414 9.0442 9.0471 9.0499 9.0527 9.0556 9.0585 9.0613 9.0642 9.0671 9.0700 9.0729 9.0758
lamda__44= 0.00255 .*(T.^2)-0.0161 .*T+8.8230e+3 %lamda %Eg(0.21)
lamda__44 = 1×148
1.0e+03 * 9.0087 9.0100 9.0114 9.0128 9.0142 9.0156 9.0170 9.0184 9.0198 9.0212 9.0227 9.0241 9.0255 9.0270 9.0284 9.0299 9.0313 9.0328 9.0343 9.0357 9.0372 9.0387 9.0402 9.0417 9.0432 9.0447 9.0462 9.0477 9.0492 9.0507
cmtx11 = [0.00255 -0.0161 8.8230e+3; 0.00472 0.0740 8.623e+03];
cmtx = cmtx11 ; % Parameter Matrix
for k = 1:size(cmtx,2)
DM = [0 1; 0.21 1]; % Design Matrix
Bx(:,k) = DM \ cmtx(:,k); % Linear Regression For Each Coefficient
Ck(:,k) = DM * Bx(:,k); % Check Results
end
% format longG
% Bx
% Ck
format shortE
lambdafcn = @(T,x) [x 1]*Bx(:,1).*(T.^2) + [x 1]*Bx(:,2).*T + [x 1]*Bx(:,3); % 'lambda' Function Incorporating Linear Regression Parameters For Each Coefficient
[xm,Tm] = ndgrid(x, T); % Create Matrices From Vectors
xv = xm(:);
Tv = Tm(:);
for k = 1:numel(xm)
lambdav(k,:) = lambdafcn(Tv(k),xv(k)); % Create Vector Of 'lambda' Values For 'scatteredInterpolant'
end
Fz = scatteredInterpolant(Tm(:), xm(:), lambdav); % Create Interpolation Function
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
x_07 = 0.07+zeros(size(T(:))); % Define 'x' Vector
Line_07 = Fz(T(:), x_07); % Interpolate Line
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation — ‘x-z’ View')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
view(90, 0)
figure
surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('T (°K)')
ylabel('x')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation — ‘y-z’ View')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
plot3(T(:), x_07, Line_07, '-r', 'LineWidth',2)
hold off
text(max(T), 0.07, max(Line_07), ' \leftarrow Line at x=0.07', 'Horiz','left', 'Vert','middle', 'Rotation',40)
view(0,0)
Use the print function with '-dpng' to save each of them as a separate image if that is what you want to do.
.
  6 Comments
Israfil
Israfil on 7 Jan 2024
Thank you for your answer,
The final version with a few edits is as follows.
I did the derivation process as follows.
If you have a different suggestion, I can take it.
T=273:1:420; %axisy
% x=0:0.1:10;
x = linspace(0, 0.35, 22);
Txm=1:1:148;
Txn=1.21:1:148.21;
Txmn=Txn-Txm; % X=0.21 (axis x measured first value)
Txk=1:1:148;
Txmk=Txk-Txm; % X=0; (axis x measured second value)
%lamda11=0.002547*(T.^2)+-0.01608*T+ 7162 ; %axis z(y) function
%lamda22=0.004723*(T.^2) +0.07403*T + 6962 ; %axis z(y) function
lamda__11= 0.00472 .*(T.^2)+0.0740 .*T+8.623e+03; %lamda %Eg(0)
lamda__44= 0.00255 .*(T.^2)-0.0161 .*T+8.8230e+3; %lamda %Eg(0.21)
cmtx11 = [0.00255 -0.0161 8.8230e+3; 0.00472 0.0740 8.623e+03];
cmtx = cmtx11 ; % Parameter Matrix
for k = 1:size(cmtx,2)
DM = [0 1; 0.21 1]; % Design Matrix
Bx(:,k) = DM \ cmtx(:,k); % Linear Regression For Each Coefficient
Ck(:,k) = DM * Bx(:,k); % Check Results
end
% format longG
% Bx
% Ck
format shortE
lambdafcn = @(T,x) [x 1]*Bx(:,1).*(T.^2) + [x 1]*Bx(:,2).*T + [x 1]*Bx(:,3); % 'lambda' Function Incorporating Linear Regression Parameters For Each Coefficient
[xm,Tm] = ndgrid(x, T); % Create Matrices From Vectors
xv = xm(:);
Tv = Tm(:);
for k = 1:numel(xm)
lambdav(k,:) = lambdafcn(Tv(k),xv(k)); % Create Vector Of 'lambda' Values For 'scatteredInterpolant'
end
Fz = scatteredInterpolant(Tm(:), xm(:), lambdav); % Create Interpolation Function
x_vals = [0, 0.05 , 0.10 , 0.15, 0.2];
x_lines = x_vals + zeros(size(T(:))) ;
for k = 1:numel(x_vals)
z_lines(:,k) = Fz(T(:), x_lines(:,k));
end
figure
% surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('Temperature (°K)')
ylabel('Radiation Wavelength (Å)')
zlabel('\lambda(T,x)')
title('\lambda(T,x) Surface With Linear Coefficient Interpolation — ‘x-z’ View')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
for k = 1:numel(x_vals)
plot3(T(:), x_lines(:,k), z_lines(:,k), '-', 'LineWidth',2, 'DisplayName',sprintf('x\\_val = %.1f',x_vals(k)))
end
legend('λ(Eg(T)) ; x=0 ','λ(Eg(T)) ; x=0.05 ','λ(Eg(T)) ; x=0.10 ','λ(Eg(T)) ; x=0.15 ','λ(Eg(T)) ; x=0.20 ');
hold off
legend('Location','best')
view(90, 0)
%-----------------------------------------------------
%figure gereksiz
% surfc(Tm, xm, Fz(Tm,xm), 'EdgeColor','interp')
colormap(turbo)
xlabel('Temperature (°K)')
ylabel('x')
zlabel('Radiation Wavelength (Å)')
title('Change of Radiation Wavelength Depending on Temperature')
axis([min(T) max(T) min(x) max(x) min(Fz(Tm,xm),[],'all') max(Fz(Tm,xm),[],'all')])
grid('on')
hold on
%for k = 1:numel(x_vals)
% plot3(T(:), x_lines(:,k), z_lines(:,k), '-', 'LineWidth',2, 'DisplayName',sprintf('x\\_val = %.1f',x_vals(k)))
%end
hold off
legend('Location','best')
view(0,0)
%------------------------------------------------------------
figure
T_05 = 400+zeros(size(x(:)));
LineT_05 = Fz(T_05, x(:));
T_06 = 390+zeros(size(x(:)));
LineT_06 = Fz(T_06, x(:));
T_07 = 360+zeros(size(x(:)));
LineT_07 = Fz(T_07, x(:));
T_08 = 330+zeros(size(x(:)));
LineT_08 = Fz(T_08, x(:));
T_09 = 300+zeros(size(x(:)));
LineT_09 = Fz(T_09, x(:));
plot(x,LineT_09, x,LineT_08, x,LineT_07, x,LineT_06, x,LineT_05, 'LineWidth',2);
legend('T=300K ; λ(Eg(x))','T=330K ; λ(Eg(x))','T=360K ; λ(Eg(x))','T=390 ; λ(Eg(x))','T=400K ; λ(Eg(x))');
title('Compensation Parameter Dependence Ratio of Radiation Wavelength ');
xlabel('Compensation Parameter (x) ');
ylabel('Radiation Wavelength (Å) ');
%----------------------------------------------------------
figure;
for n=1:5
for m = 1:148
if(n==1)
z1(n,m) = z_lines(m,n);
elseif(n==2)
z2(1,m) = z_lines(m,n);
elseif(n==3)
z3(1,m) = z_lines(m,n);
elseif(n==4)
z4(1,m) = z_lines(m,n);
elseif(n==5)
z5(1,m) = z_lines(m,n);
else
end
end
end
T1=273:1:419
T1 = 1×147
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
z11=diff(z1);
z12=diff(z2);
z13=diff(z3);
z14=diff(z4);
z15=diff(z5);
plot(T1,z11, T1,z12, T1,z13, T1,z14, T1,z15, 'LineWidth',2);
axis([ 293 400 0 5]);
%legend('T=300K ; λ(Eg(x))','T=330K ; λ(Eg(x))','T=360K ; λ(Eg(x))','T=390 ; λ(Eg(x))','T=400K ; λ(Eg(x))');
legend('∂λ/∂(Eg(T)) ; x=0.20' ,'∂λ/∂(Eg(T)) ; x=0.15' ,'∂λ/∂(Eg(T)) ; x=0.10' ,'∂λ/∂(Eg(T)) ; x=0.05' ,'∂λ/∂(Eg(T)) ; x=0' )
title('Rate of Wavelength Change Depending on Temperature');
xlabel('Temperature (°K)');
ylabel('Wavelength Change Rate');
Star Strider
Star Strider on 7 Jan 2024
As always, my pleasure!
Those plots look great! I did not completely understand all the plots you wanted, however I am happy that my code allowed you to get the necessary information from your data to plot them.
The only suggestion I have is that using gradient rather than diff for numerical differentiation is usually preferable, since gradient produces an output the same size as the input, while diff produces an output that is one element less in the dimnensions along which it operates. The gradient values are also more reliable.

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!