How can I plot an X-Z slice of a Surface Plot on a given Y value

10 ビュー (過去 30 日間)
Shelton Ware
Shelton Ware 2022 年 5 月 24 日
回答済み: sai charan sampara 2023 年 10 月 11 日
I have attempted to do this by using contour3 and contourslice but I have not gotten it to work. I would like to create a X-Z plane slice of the fitted surface plot for a given Y value. (I am not able to include the data to run this specific case)
idx = ET>770 & ET<900; % Approx. time range for 2deg camber and 12psi
Unrecognized function or variable 'ET'.
SAe = -SA(idx);
FZe = -FZ(idx);
FYe = FY(idx);
xdata = [SAe FZe];
ydata = FYe;
[FY4, f_resnorm, f_residual] = lsqcurvefit('Pacejka4_Model', x0, xdata, ydata, [], [], options);
fz = linspace(-200, -1600, 100)';
sa = linspace(-13, 13, 100)';
fy = zeros(length(sa),length(fz));
x0 = [0.0817 -0.5734 -0.5681 -0.1447]; % Pacejka4 Parameter
options = optimoptions('lsqcurvefit', 'MaxFunctionEvaluations', 10e9, 'StepTolerance',1e-10);
[FY4(2,:),f_resnorm(2),f_residual(:,2)] = lsqcurvefit('Pacejka4_Model', x0, xdata, ydata, [], [], options);
for i=1:length(fz)
fy(i,:,2) = Pacejka4_Model(FY4(2,:), [sa fz(i)*ones(100,1)]);
end
figure
plot3(SAe,FZe,FYe,'-k')
grid on
title("Tire")
hold on
surf(sa,fz,fy(:,:,2))
hold off
Here was my attempt to use contourslice.
yslice = [-300];
V = contour3(sa,fz,fy(:,:,2),100);
[X,Y,Z] = meshgrid(100:0.1:-100);
contourslice(X,Y,Z,V,[],yslice,[])
  2 件のコメント
Torsten
Torsten 2022 年 5 月 24 日
You'll only get a one-dimensional curve by cutting a surface by a plane. Is this really what you want ?
Shelton Ware
Shelton Ware 2022 年 5 月 25 日
To my undestanding I should get a graph representative of the function on the X and Z axis with the coresponding Y value.

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

回答 (1 件)

sai charan sampara
sai charan sampara 2023 年 10 月 11 日
Hello Shelton,
I understand that you are trying to plot an X-Z slice of a surface plot for a given value of y.
This can be achieved by using logical indexing. Logical indexing involves finding out the indices of all the elements of an array which satisfy a certain logical condition. Using this we can find out the indices/positions of the required y value in the y data array and use them to traverse through x and z data to get a 2 D plot. This plot will be in the shape of the slice obtained when the surface plot is cut along the plane of y equal to the required y value. Here is the working on an example data and surface plot:
[X,Y,Z] = peaks(25);
CO(:,:,1) = zeros(25); % red
CO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % green
CO(:,:,3) = ones(25).*linspace(0,1,25); % blue
surf(X,Y,Z,CO)
figure;
idx=(Y==0);
plot(X(idx),Z(idx));
Here “idx” is the index variable that was obtained by logical indexing on the y data array “Y”. Then it was used on the data points “X” and “Z” to get the required plot.
You can refer to the below documentation to learn more about logical indexing in an array.
Hope this helps.
Thanks,
Charan.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by