无法在Matlab 7中为我的程序获取图形. [英] Cant get graphs in Matlab 7 for my program.

查看:76
本文介绍了无法在Matlab 7中为我的程序获取图形.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用2类和2属性数据集.我似乎无法获得想要的图形.

我得到3次警告:Z一定不能是标量或向量,不能渲染表面".

图的窗口确实出现,其中没有任何图.
Data2.txt中的数据示例(6个实例)为:

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

代码如下:

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);

推荐答案

正确,在Matlab 7.9.0中,这给出了以下更有用的错误:

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只是我将您的代码放入其中的文件的名称).

这告诉我,您需要检查要传递给surf的内容.

我认为问题出在这里:



(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的计算结果为-0.2476,而不是列表.这会导致x和y变成缩放器,并且从那里全部出错.

如果将其更改为-3*sd1:0.001:3*sd1,(请注意,花了相对较长的时间才能在Uni服务器上执行...),我将收到一个图表.我希望这有助于找出要解决的问题.

只是一些注意事项:

0.将代码放入< pre>或< code>标签(分别使用代码块"或行内代码"按钮).
1.查看numel以改进此行:



-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.目前,您仅会看到最后一个图形,因为每个surf都会覆盖前一个图形.要么将所有绘图都放在一页上,要么使用pause命令使Matlab等待每个绘图之间的任何按键.

希望对您有帮助.


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.


您不想要的到底是什么.

警告不应该停止它的运行,它只是暗示您可能做错了什么.另外,该警告文字正确吗?这对我来说真的没有意义.

同样,data2.txt中的示例也将有助于重现您的问题.
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.


我更新了问题,添加了示例数据,并与样本数据.
I have updated my question, included a sample data, and also sync''d the code with that sample data.


这篇关于无法在Matlab 7中为我的程序获取图形.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆