Azzera filtri
Azzera filtri

Error in Matlab trying to perform mesh grid

4 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Walter Roberson
Walter Roberson il 31 Mar 2021
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 Commenti
Shao Yang Zhang
Shao Yang Zhang il 1 Giu 2021
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 il 1 Giu 2021
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by