kideve 发表于 2007-8-1 12:02

使用 reshape 函数出错

我的程序是:
clear
load lxy.dat;
=size(lxy);
x=lxy(:,1);
y=lxy(:,2);
f=lxy(:,3);
z=reshape(f,m,n)
surf(x,y,z)


我的dat文件是:
0.260257 0.016201 500000.000000
0.260179 0.015014 500000.000000
0.259818 0.013084 500000.000000
0.259635 0.010988 500000.000000
0.259792 0.008933 500000.000000
0.259902 0.006942 500000.000000
0.259969 0.004968 500000.000000
0.260000 0.002989 500000.000000

但运行后就是出现
??? Error using ==> reshape
To RESHAPE the number of elements must not change.

请知道的大哥大姐告诉我一下,如何修改!!!谢谢!!

[ 本帖最后由 eight 于 2007-8-2 13:11 编辑 ]

w89986581 发表于 2007-8-1 12:35

z=reshape(f,m,n),要求f中元素个数等于mn个.

[ 本帖最后由 w89986581 于 2007-8-1 12:36 编辑 ]

HolySaint 发表于 2007-8-1 14:21

RESHAPE Change size.
   RESHAPE(X,M,N) returns the M-by-N matrix whose elements
    are taken columnwise from X.An error results if X does
    not have M*N elements.
   RESHAPE(X,M,N,P,...) returns an N-D array with the same
    elements as X but reshaped to have the size M-by-N-by-P-by-...
    M*N*P*... must be the same as PROD(SIZE(X)).
   RESHAPE(X,) is the same thing.
   RESHAPE(X,...,[],...) calculates the length of the dimension
    represented by [], such that the product of the dimensions
    equals PROD(SIZE(X)). PROD(SIZE(X)) must be evenly divisible
    by the product of the known dimensions. You can use only one
    occurrence of [].
   In general, RESHAPE(X,SIZ) returns an N-D array with the same
    elements as X but reshaped to the size SIZ.PROD(SIZ) must be
    the same as PROD(SIZE(X)).





xjzuo 发表于 2007-8-1 17:23

去掉 z=reshape(f,m,n); 将surf(x,y,z)改为plot3(x,y,z).
若要进行曲面拟合,help griddata;也可以用样条曲面拟合.
---另:你的数据似乎给得太少.
页: [1]
查看完整版本: 使用 reshape 函数出错