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
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!