声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1388|回复: 3

[编程技巧] 使用 reshape 函数出错

[复制链接]
发表于 2007-8-1 12:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我的程序是:
clear
load lxy.dat;
[m,n]=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 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-8-1 12:35 | 显示全部楼层
z=reshape(f,m,n),要求f中元素个数等于mn个.

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

评分

1

查看全部评分

发表于 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,[M N P ...]) 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)).
发表于 2007-8-1 17:23 | 显示全部楼层
去掉 z=reshape(f,m,n); 将surf(x,y,z)改为plot3(x,y,z).
若要进行曲面拟合,help griddata;也可以用样条曲面拟合.
---另:你的数据似乎给得太少.
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-12 08:34 , Processed in 0.059888 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表