MATLAB: I keep getting this error “Error using contour (line 48) Z must be at least a 2×2 matrix. Error in Test2Prob1 (line 73) contour(X,Y,Z,6);” please what am i doing wrong contourplot x = linspace(-3,3);y = linspace(-3.5,3.5);[X,Y] = meshgrid(x,y); Z = ((x.^2 – 1)+ (y.^2 -4) +(x.^2 -1).* (y.^2 -4))./((x.^2 + y.^2 + 1).^2) contour(X,Y,Z,6); Best Answer You create the grids but you calculate with the vectors. Change your Z to use X and Y Related SolutionsMATLAB: Contour plot for given x,y,z [num,txt,raw] = xlsread('Book1.xlsx') ; x = num(:,1) ; y = num(:,2) ; z = num(:,3) ; figure(1)scatter(x,y,20,z,'filled') ; colorbar%% Method 1 / Griddatanx = 500 ; ny = 500 ;[X,Y] = meshgrid(linspace(min(x),max(x),nx),linspace(min(y),max(y),ny)) ;Z =griddata(x,y,z,X,Y) ;figure(2)contour(X,Y,Z) ;figure(3)pcolor(X,Y,Z)shading interp %% Method 2 simple reshaping x = unique(x) ; nx = length(x) ;y = unique(y) ; ny = length(y) ;Z = reshape(z,ny,nx) ;figure(4)contour(x,y,Z) MATLAB: Surfnorm function shows error X, Y, and Z must be 2D matrices. Z is a function of X and Y in this case. The following shows an example of how to use it properlyx = linspace(-1,1,10);y = x;[X,Y]=meshgrid(x,y);Z = X+Y; % Z=X+Y is chosen as an example to show Z is a function of X and Yfigure,surfnorm(X,Y,Z); Related QuestionContour from .xlsx, getting “Z must be at least a 2×2 matrix” errorUnderstanding how to use the function griddataSub2ind gives error: Error using sub2ind (line 73) Out of range subscript.
Best Answer