Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with 2-class and 2-attributes dataset. I cannot seem to get the graphs I want.

I get this 3 times "Warning: Z must not be a scalar or vector, not rendering surface."

The window for the graph does appear containing no graph in it.
Sample (6 instances) of data in the Data2.txt is:

0.55 0.44 19
0.68 0.55 19
0.7 0.535 19
0.53 0.415 20
0.595 0.475 20
0.725 0.575 20

Code is in the following:

clear;
[x1,x2,w]=textread('Data2.txt','%f %f %d' );
l=[1 0;0 1];
cw1=1;
cw2=1;
for(i=1:6)
    if(w(i)==19)
        x1w1(cw1)=x1(i);
        x2w1(cw1)=x2(i);
        cw1=cw1+1;
    else
        x1w2(cw2)=x1(i);
        x2w2(cw2)=x2(i);
        cw2=cw2+1;
    end
end
cw1=cw1-1;
cw2=cw2-1;
pw1=cw1/6;
pw2=1-pw1;
u1=[mean(x1w1); mean(x2w1)];
u2=[mean(x1w2); mean(x2w2)];
sig1=cov(x1w1,x2w1);
sig2=cov(x1w2,x2w2);
sd1=sqrt(abs(var(x1)));
sd2=sqrt(abs(var(x2)));
[x,y]=meshgrid(-3*sd1:1:3*sd1, -3*sd2:1:3*sd2);
x=x';
for(i=1:size(x,1))
    for(j=1:size(y,1))
    pxw1(i,j)=exp(-0.5*([x(i,1);y(1,j)]-u1)'*inv(sig1)*([x(i,1);y(1,j)]-u1))/(2*pi*sqrt(det(sig1)));
    pxw2(i,j)=exp(-0.5*([x(i,1);y(1,j)]-u2)'*inv(sig2)*([x(i,1);y(1,j)]-u2))/(2*pi*sqrt(det(sig2)));
    end
end
px=pxw1*pw1+pxw2*pw2;
pw1x=pw1*pxw1./px;
pw2x=pw2*pxw2./px;
lhr=pxw1./pxw2;
ra1x=l(1,1).*pw1x+l(1,2).*pw2x;
ra2x=l(2,1).*pw1x+l(2,2).*pw2x;

surf(pxw1);

surf(pxw2);

surf(pw1x);

surf(pw2x);

surf(lhr);

surf(ra1x);

surf(ra2x);
Posted
Updated 13-Jan-10 1:37am
v5

Right, in Matlab 7.9.0 this gives the following more useful error:

Error using ==> surf at 78
Z must be a matrix, not a scalar or vector.

Error in ==> testforcp at 43
surf(pxw1);


(testforcp is just the name of the file I've put your code in).

This tells me that you need to review what you're passing to surf.

I think the problem is here:

[x,y]=meshgrid(-3*sd1:1:3*sd1, -3*sd2:1:3*sd2)


-3*sd1:1:3*sd1 evaluates to -0.2476, not a list. This causes x and y to become scalers, and it all goes wrong from there.

If I changed it to -3*sd1:0.001:3*sd1, (be warned, took a relatively long time to execute on my Uni servers...) I received a graph out. I hope this helps track down what to fix.

Just a couple of notes:

0. Put code in <pre> or <code> tags (use the 'code block' or 'inline code' buttons respectively).
1. Look in to numel to improve this line:
for(i=1:6)

2. At the moment you'll only see the last graph, as each surf overwrites the previous one. Either look in to putting all the plots on to one page, or use the pause command to make Matlab wait for any key press between each plot.

I hope this all helps.
 
Share this answer
 
What precisely is it doing that you don't want.

A Warning shouldn't stop it running, it's just suggesting you might have done something wrong. Also, is that warning text right? It doesn't really make sense to me.

Also, a sample of what is in data2.txt would be useful to reproduce your problem.
 
Share this answer
 
I have updated my question, included a sample data, and also sync'd the code with that sample data.
 
Share this answer
 
Thank you Tony Richards, with your tip and help of my university friend I was able to pin point the problem, now I get the graphs. I had to replace this line;
[x,y]=meshgrid(-3*sd1:1:3*sd1, -3*sd2:1:3*sd2);

With the correct one, that is;
[x,y]=meshgrid(-3*sd1:0.005:3*sd1, -3*sd2:0.005:3*sd2);

And about the graphs, using the operator figure before each surf I was able to get a separate window for every graph.

Thanks again!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900