Matlab error "Z must be size 2x2 or greater"

6 views (last 30 days)
Wendell
Wendell on 25 Jun 2017
Commented: John BG on 27 Jun 2017
Can anyone help me with this code, I kept on getting a error (Z must be size 2x2 or greater),
% Plot contours of ground-level Zn concentration.
figure(1)
clist = [ 0.001, 0.01, 0.02, 0.05, 0.1 ];
glc2 = glc*1e6; % convert concentration to mg/m^3
[c2, h2] = contourf( xmesh, ymesh, glc2, clist );
clabel(c2, h2, 'FontSize', smallfont-2 )
colormap(1-winter)
colorbar
set(gca, 'XLim', xlim ), set(gca, 'YLim', ylim )
xlabel('x (m)'), ylabel('y (m)')
title(['Zn concentration (mg/m^3), max = ', sprintf('%5.2f', max(glc2(:)))])
grid on
The error reads like this:
Error using contourf (line 66)
Z must be size 2x2 or greater.
Error in forward2 (line 47)
[c2, h2] = contourf( xmesh, ymesh, glc2, clist );
I would appreciate any advise
Thanks much.
  1 Comment
John BG
John BG on 27 Jun 2017
both contour and contourf
require at least input Z.
Your variable glc is not same size as X and Y, it's not a Z with same size as X and Y, please define glc as used so far.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 25 Jun 2017
You have
glc2 = glc*1e6; % convert concentration to mg/m^3
but we have no idea what size glc is. Whatever it is is likely either a scalar or a vector instead of being a 2D array that is at least 2 x 2.

Community Treasure Hunt

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

Start Hunting!