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

20 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Steven Lord
Steven Lord am 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 Kommentar
Tyler Stephen Kuehn
Tyler Stephen Kuehn am 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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by