Error using mesh - Z must be a matrix, not a scalar or vector, using mesh command
1 次查看(过去 30 天)
显示 更早的评论
Dear community,
I am using this code to create a scatter plot in three dimensions using the attached data. However, I encountered the following error: "Error using mesh - Z must be a matrix, not a scalar or vector." It appears to be related to the values of the vector p21. When I multiply it by 100, the code works fine. However, I require the original data. Could anyone assist me with this? Additionally, I would like to make the interpolating plane transparent.
Thank you in advance!
clc; clear;close all;
load ('data')
x1 = p21;
x2 = vp;
y = ucs;
X = [ones(size(x1)) x1 x2 x1.*x2];
b = regress(y,X)
scatter3(x1,x2,y,'filled')
hold on
x1fit = min(x1):100:max(x1);
x2fit = min(x2):10:max(x2);
[X1FIT,X2FIT] = meshgrid(x1fit,x2fit);
YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT;
mesh(X1FIT,X2FIT,YFIT)
xlabel('P21 [m/m2]')
ylabel('Vp [m/s]')
zlabel('UCS [MPa]')
view(50,10)
hold off
[~,~,~,~,stats] = regress(y,X)
0 个评论
采纳的回答
Dyuman Joshi
2024-3-26
编辑:Dyuman Joshi
2024-3-26
The difference between min(x1) and max(x1) is not 100, thus the vector x1fit generated via colon() is just min(x1). Consequently, YFIT is not a 2x2 matrix as expected by mesh() (or surf() for that matter)
load('data.mat')
x1 = p21;
x2 = vp;
y = ucs;
X = [ones(size(x1)) x1 x2 x1.*x2];
b = regress(y,X)
scatter3(x1,x2,y,'filled')
hold on
%Values for verification
min(x1)
max(x1)
%Generate 50 points in between min and max values using linspace()
x1fit = linspace(min(x1), max(x1), 50);
x2fit = linspace(min(x2), max(x2), 50);
[X1FIT,X2FIT] = meshgrid(x1fit,x2fit);
YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT;
mesh(X1FIT,X2FIT,YFIT)
xlabel('P21 [m/m2]')
ylabel('Vp [m/s]')
zlabel('UCS [MPa]')
view(50,10)
hold off
[~,~,~,~,stats] = regress(y,X)
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!