getting error in mesh plot

조회 수: 4 (최근 30일)
Ehtisham
Ehtisham 2024년 1월 15일
댓글: Dyuman Joshi 2024년 1월 15일
% Provided data
KFmax = [20, 40, 60, 80, 100];
KBmax = [20, 40, 60, 80, 100];
KBmax100 = [43.50297072, 46.52477297, 44.39002998, 41.32192544, 38.27960907];
KBmax80 = [41.24659136, 42.59908012, 39.69352292, 36.31204481, 33.18494278];
KBmax60 = [37.40881927, 36.83773483, 33.27098581, 29.76062133, 26.73705543];
KBmax40 = [30.46172094, 27.88434423, 24.07279092, 20.89331763, 18.36534748];
% Create a meshgrid
[X, Y] = meshgrid(KFmax, KBmax);
% Create a 3D surface mesh plot
figure;
surf(X, Y, KBmax100, 'FaceAlpha', 0.5);
hold on;
surf(X, Y, KBmax80, 'EdgeColor', 'k');
surf(X, Y, KBmax60, 'EdgeColor', 'r');
surf(X, Y, KBmax40, 'EdgeColor', 'g');
% Customize the plot
title('R*peak');
xlabel('KFmax');
ylabel('KBmax');
zlabel('R*peak');
grid on;
% Set axis limits
xlim([20, 100]);
ylim([20, 100]);
zlim([0, 100]);
% Set custom x and y ticks
xticks([20, 40, 60, 80, 100]);
yticks([20, 40, 60, 80, 100]);
% Display the legend
legend('KBmax100', 'KBmax80', 'KBmax60', 'KBmax40', 'Location', 'Best');
% Display the grid
grid on;
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2024년 1월 15일
surf(X, Y, Z)
When using this syntax where X and Y are matrices, Z must be a matrix of the same size.
Which is not the case here, thus you get the error.
A general solution is to ensure that Z is of the same size as X and Y.
A particular solution might be to use scatteredInterpolant or griddedInterpolant to generate the corresponding Z matrix.

댓글을 달려면 로그인하십시오.

답변 (1개)

Hassaan
Hassaan 2024년 1월 15일
@Ehtisham Try this:
% Provided data
KFmax = [20, 40, 60, 80, 100];
KBmax = [20, 40, 60, 80, 100];
KBmax100 = [43.50297072, 46.52477297, 44.39002998, 41.32192544, 38.27960907];
KBmax80 = [41.24659136, 42.59908012, 39.69352292, 36.31204481, 33.18494278];
KBmax60 = [37.40881927, 36.83773483, 33.27098581, 29.76062133, 26.73705543];
KBmax40 = [30.46172094, 27.88434423, 24.07279092, 20.89331763, 18.36534748];
% Create a meshgrid
[X, Y] = meshgrid(KFmax, KBmax);
% Repeat KBmax100 to match the dimensions of X and Y
KBmax100_matrix = repmat(KBmax100, [5, 1]);
% Create a 3D surface mesh plot
figure;
surf(X, Y, KBmax100_matrix, 'EdgeColor', 'k');
colormap('jet'); % Adjust the colormap as needed
% Customize the plot
title('R*peak');
xlabel('KFmax');
ylabel('KBmax');
zlabel('R*peak');
grid on;
% Set axis limits
xlim([20, 100]);
ylim([20, 100]);
zlim([min(KBmax100_matrix(:)), max(KBmax100_matrix(:))]);
% Set custom x and y ticks
xticks([20, 40, 60, 80, 100]);
yticks([20, 40, 60, 80, 100]);
% Display the color bar
colorbar;
% Display the grid
grid on;
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by