Can't figure out the error in my pcolor line, keep getting color data input must be a matrix error

21 views (last 30 days)
xvalues =[-15.0:0.25:15.0]';
gvalues = gzx(xvalues,p,z); %evaluates xvalues for a defined function for a constant p & z (function is defined later in the code)
Xdata = [xvalues, gvalues];
XLB = [3.5; 7500]
XUB = [7.0; 12500]
%... Calculate grid to plot hump function
opt=0;
DX1=0.03;
DX2=10;
[x1, x2] = meshgrid(XLB(1):DX1:XUB(1),XLB(2):DX2:XUB(2));
[M0,N0]=size(x1);
xx1=x1(:);
xx2=x2(:);
n=size(xx1,1);
for ii=1:n
fplot(ii)=costfunct([xx1(ii);xx2(ii)],Xdata);
end
fplot=reshape(fplot,M0,N0);
%plot
hf = figure();
colormap jet;
pcolor(x1,x2,fplot);
shading interp
hold on

Accepted Answer

Steven Lord
Steven Lord on 23 Sep 2020
Please run this command immediately before the line where you call pcolor and show us the output from just before the pcolor call that throws the error.
whos x1 x2 fplot
My suspicion is that fplot was initialized to something that's not numeric (like a sym array) and can't be converted into a double array in order to be used in pcolor, something like x in the example below.
x = sym('x', [10 10]);
pcolor(1:10, 1:10, x)
  1 Comment
Tyler Stephen Kuehn
Tyler Stephen Kuehn on 23 Sep 2020
Name Size Bytes Class Attributes
fplot 161x117 150696 double
x1 161x117 150696 double
x2 161x117 150696 double
for some reason when I put the whos command in there and change nothing else it now works, and the plot is showing up as expected. Not sure why but Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!