Error in Matlab trying to perform mesh grid
4 ビュー (過去 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!