Error in Matlab trying to perform mesh grid

4 ビュー (過去 30 日間)
Shao Yang Zhang
Shao Yang Zhang 2021 年 3 月 31 日
コメント済み: Walter Roberson 2021 年 6 月 1 日
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)

採用された回答

Walter Roberson
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.
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 件のコメント
Shao Yang Zhang
Shao Yang Zhang 2021 年 6 月 1 日
Thank you for your response. I'm quite overwhelmed by all the information povided from the last post and would like some clarification:
  1. How can I tell if my data is rolled or unrolled? Should I navigate to workspace to determine the dataset organization?
  2. When ran the code, the image I got was contoured lines (Figure Attached). Does that indicate the data fell into a natural grid?
  3. When referring to estimating the working surface and drawing appropriate contour, can you elaborate on how I can accomplish this aspect? The contour plot did not fill the graph's window and lines were predetermined. It would be beneficial to know how I can alter the window size for the plot to fill the window and determine the depth of each contour line.
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);
colorbar;
Walter Roberson
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 ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by