声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4271|回复: 18

[综合讨论] 关于reshape命令

[复制链接]
发表于 2008-8-4 10:30 | 显示全部楼层 |阅读模式

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

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

x
我输入了一个变量数据,输入进去是1402200×1,想将这个变成一个三维的a×b×c,数据是原先是91×71×300的,现在reshape成这样,数据明显不对呀,不知道为何
回复
分享到:

使用道具 举报

发表于 2008-8-4 11:35 | 显示全部楼层

回复 楼主 的帖子

数据是原先是91×71×300的
这句话什么意思
 楼主| 发表于 2008-8-4 14:17 | 显示全部楼层
就是我选取的数据经纬度的格点是91个和71个,300是时间长度,300个月,总的数据长度是91×71×300,但是明显的91×71×300>1402200×1,所以有To RESHAPE the number of elements must not change.这样的错误命令
发表于 2008-8-4 14:19 | 显示全部楼层

回复 3楼 的帖子

都知道数据长度不等了,还有什么问题
 楼主| 发表于 2008-8-4 14:33 | 显示全部楼层
就是不知道为什么不等,查不出原因来
发表于 2008-8-4 14:36 | 显示全部楼层
是不是将91×71×300变成1维数据

B = reshape(A,m,n) returns the m-by-n matrix B whose elements are taken column-wise from A. An error results if A does not have m*n elements.

B = reshape(A,m,n,p,...) or B = reshape(A,[m n p ...]) returns an n-dimensional array with the same elements as A but reshaped to have the size m-by-n-by-p-by-.... The product of the specified dimensions, m*n*p*..., must be the same as prod(size(A)).

B = reshape(A,...,[],...) calculates the length of the dimension represented by the placeholder [], such that the product of the dimensions equals prod(size(A)). The value of prod(size(A)) must be evenly divisible by the product of the specified dimensions. You can use only one occurrence of [].

B = reshape(A,siz) returns an n-dimensional array with the same elements as A, but reshaped to siz, a vector representing the dimensions of the reshaped array. The quantity prod(siz) must be the same as prod(size(A)).
 楼主| 发表于 2008-8-4 14:41 | 显示全部楼层
就是将数据变成一维,然后再reshape回来三维来,可是数据大小是不对的

[ 本帖最后由 蜜雪儿 于 2008-8-4 14:42 编辑 ]
发表于 2008-8-4 15:32 | 显示全部楼层

回复 7楼 的帖子

B = reshape(A,m,n)
这里的m.n就是要让你填的

跟你说了那么多
你还是把你的程序贴上来吧
发表于 2008-8-4 16:09 | 显示全部楼层
问题描述不清 :@(
 楼主| 发表于 2008-8-5 08:54 | 显示全部楼层
xl=81;
yl=56;
tl=305;
fid = fopen('H:\eof\sstxin.dat','rb'); %打开文件,二进制
hc = fread(fid,Inf,'float'); %inf:正无穷,全部读入,变量原来排放顺序:经度,纬度,高度,变量,时次
hc = reshape(hc,xl*yl,tl);%改变维数,成为m*n的矩阵,m为观测点个数,n为时刻数
fclose(fid);
--------------------------------------------------------------------------------
以上sstxin.dat的数据就是81×56×305的-----运行后有错误

[ 本帖最后由 蜜雪儿 于 2008-8-5 08:55 编辑 ]
发表于 2008-8-5 09:19 | 显示全部楼层
fid = fopen('H:\eof\sstxin.dat','rb'); %打开文件,二进制
[xl,yl,tl]=size(fid);
hc = fread(fid,Inf,'float'); %inf:正无穷,全部读入,变量原来排放顺序:经度,纬度,高度,变量,时次
hc = reshape(hc,xl*yl,tl);%改变维数,成为m*n的矩阵,m为观测点个数,n为时刻数
fclose(fid);

这样试试
 楼主| 发表于 2008-8-5 15:11 | 显示全部楼层
xl=81;
>> yl=56;
>> tl=305;
>> fid = fopen('H:\eof\sstxin.dat','rb'); %打开文件,二进制
>> [tl,xl,yl]=size(fid);
>> hc = fread(fid,Inf,'float'); %inf:正无穷,全部读入,变量原来排放顺序:经度,纬度,高度,变量,时次
>> hc = reshape(hc,xl*yl,tl);%改变维数,成为m*n的矩阵,m为观测点个数,n为时刻数
??? Error using ==> reshape
To RESHAPE the number of elements must not change-----------------还是有错误
发表于 2008-8-5 15:32 | 显示全部楼层
>> a=rand(3,3,3)
a(:,:,1) =
    0.8147    0.9134    0.2785
    0.9058    0.6324    0.5469
    0.1270    0.0975    0.9575

a(:,:,2) =
    0.9649    0.9572    0.1419
    0.1576    0.4854    0.4218
    0.9706    0.8003    0.9157

a(:,:,3) =
    0.7922    0.0357    0.6787
    0.9595    0.8491    0.7577
    0.6557    0.9340    0.7431
>> [x,y,z]=size(a)
x =
     3

y =
     3

z =
     3
>> b=reshape(a,x*y,z)
b =
    0.8147    0.9649    0.7922
    0.9058    0.1576    0.9595
    0.1270    0.9706    0.6557
    0.9134    0.9572    0.0357
    0.6324    0.4854    0.8491
    0.0975    0.8003    0.9340
    0.2785    0.1419    0.6787
    0.5469    0.4218    0.7577
    0.9575    0.9157    0.7431

我用随即矩阵试了下,没有问题
你还是把数据一并传上来吧
 楼主| 发表于 2008-8-5 15:54 | 显示全部楼层
数据怎么传呢,挺大的,要5M多,如果这样试试也没错的话,为什么我的程序老是错误呢

[ 本帖最后由 蜜雪儿 于 2008-8-5 15:56 编辑 ]
 楼主| 发表于 2008-8-5 16:03 | 显示全部楼层
fid = fopen('H:\eof\sstxin.dat','rb'); %打开文件,二进制
>> [tl,xl,yl]=size(fid);
>> [tl,xl,yl]=size(fid)

tl =

     1


xl =

     1


yl =

     1
--------------------------------试了下,这一步首先就是错的
那么大的数据,不可能是1的,而且数据我也用别的画图软件打开过,并画过图,是没有问题的,难道是我的matlab有问题?

[ 本帖最后由 蜜雪儿 于 2008-8-5 16:04 编辑 ]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-23 05:34 , Processed in 0.055984 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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