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

19 次查看(过去 30 天)
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

采纳的回答

Steven Lord
Steven Lord 2020-9-23
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 个评论
Tyler Stephen Kuehn
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by