Error in Matlab trying to perform mesh grid
5 次查看(过去 30 天)
显示 更早的评论
Hi! I am relatively new to Matlab and have been trying to get an indepth look/analysis into my excel data set by performing contour plots and heat maps. I'm trying to extract individual columns (x,y) and the variable of interest (Z) from the excel spreadsheet and generating contour plots and heat maps. However, I'm currently getting this error message with the following code.
"Error using meshgrid (line 59)
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row
subscript and a variable subscript, as in t(rows,vars). To select variables, use t(:,i) or for
one variable t.(i). To select rows, use t(i,:).
Error in Specimen_84_HeatMap (line 5)
[X,Y] = meshgrid(x,y); "
Specimen_84 = readtable ('Specimen_84.xlsx');
x = Specimen_84(:,17);
y = Specimen_84(:,18);
[X,Y] = meshgrid(x,y);
Z = Specimen_84(:,11);
figure
contour (X,Y,Z)
0 个评论
采纳的回答
Walter Roberson
2021-3-31
Specimen_84 = readtable ('Specimen_84.xlsx');
x = Specimen_84{:,17};
y = Specimen_84{:,18};
[X,Y] = meshgrid(x,y);
Z = Specimen_84{:,11};
figure
contour (X,Y,Z)
However, this is not going to work. You are extracting as many Z as you have X or Y, but when you meshgrid you are creating an array which is (number of x) by (number of y), and contour would expect Z to be the same size.
You probably need to to use the X, Y, Z information as inputs to a scattered interpolant.
You could use https://www.mathworks.com/matlabcentral/fileexchange/38858-contour-plot-for-scattered-data or you could use
N = 50; %adjust as desired. This is the resolution.
Specimen_84 = readtable ('Specimen_84.xlsx');
x = Specimen_84{:,17};
y = Specimen_84{:,18};
z = Specimen_84{:,11};
[X,Y] = meshgrid(linspace(min(x), max(x), N), linspace(min(y),max(y),N));
F = scatteredInterpolant(x, y, z);
Z = F(X, Y);
figure
contour(X,Y,Z)
4 个评论
Walter Roberson
2021-6-1
Try this:
nux = length(uniquetol(x));
nuy = length(uniquetol(y));
if nux * nuy == numel(z)
fprintf('z is probably a natural grid\n');
else
fprintf('z is probably NOT a natural grid\n')
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!