Error in Matlab trying to perform mesh grid
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shao Yang Zhang
il 31 Mar 2021
Commentato: Walter Roberson
il 1 Giu 2021
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 Commenti
Risposta accettata
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.
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 Commenti
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
Più risposte (0)
Vedere anche
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!