声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1069|回复: 5

[编程技巧] matlab文件操作问题,在线等~~~

[复制链接]
发表于 2011-2-25 20:31 | 显示全部楼层 |阅读模式

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

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

x
各位在下有礼了~
在做大矩阵操作的问题,但又不是稀疏矩阵,所以只好自己写代码用外部存储器的方法来存储成临时文件。问题是如何修改文件中特定位置的数据:
可以用fseek()到指定的位置,但是在fwrite的时候有问题,如果打开文件fopen()时用的‘w+’就会覆盖以前的数据,用'a+'就会将数据添加到原来文件的后面。并且又不可能将数据全部读出来后修改再写进去,因为本来就是因为数据量太大才存到磁盘上的。
所以请教各位啊有什么方法可以解决
回复
分享到:

使用道具 举报

发表于 2011-2-25 22:19 | 显示全部楼层
本帖最后由 ChaChing 于 2011-2-25 22:20 编辑
...如何修改文件中特定位置的数据...

水平有限, 認知好像不行, 沒搜索, 直接等高手看看!
...只好自己写代码用外部存储器的方法来存储成临时文件...

好奇矩陣多大! 都可以寫出去了, 為何沒读入!?
发表于 2011-2-28 13:20 | 显示全部楼层
印象里,fortran可以....matlab么,回头help去
发表于 2011-2-28 13:43 | 显示全部楼层
help 中有这样一段内容 Exporting to Text Data Files
如下:
the contents of the file:

   16     5     9     4
    2    11     7    14
    3    10     6    15
   13     8    12     1
   55    55    55    55

Example — Overwriting an Existing Text File.  Replace the third line of the file changing.txt from the previous example with [33 33 33 33]:

replaceLine = 3;
myformat = '%5d %5d %5d %5d\n';

% Open the file with permission to read and update.
% Use fgetl, which reads a line at a time,
% to place the file position indicator at the third line.

fid = fopen('changing.txt','r+');
for k=1:(replaceLine-1);
    fgetl(fid);
end;

% call fseek between read and write operations
fseek(fid, 0, 'cof');

% print the new values
fprintf(fid, myformat, [33 33 33 33]);

% close the file
fclose(fid);

To view the file, use the type function:

type changing.txt

This command returns the new contents of the file:

   16     5     9     4
    2    11     7    14
   33    33    33    33
   13     8    12     1
   55    55    55    55

评分

1

查看全部评分

发表于 2011-2-28 13:53 | 显示全部楼层
不知你的大矩阵是几维的,2维数组还是比较好操作的,三维以上很容易晕...我脑子不够使的时候都得用积木摆摆...

之前做过的大矩阵,2d的很难溢出,都是到4d了才老溢出
尽量用小变量多做循环一层层更新,这样运行起来只有这一个大数组折腾
重新调整一下程序看看,大矩阵的情况下,有时得回避matlab最擅长的矩阵操作

另外,用feature memstats 看一下,是不是把最大连续空间都用光了,有时候关掉重开也能用的

既然能把这数据读进来,就应该能操作吧,除非你每次只读入一部分....

评分

1

查看全部评分

发表于 2011-3-5 11:19 | 显示全部楼层
回复 4 # curb 的帖子
...for k=1:(replaceLine-1), fgetl(fid); end; ...

好像也是在读了!
若会处理的在很后面, 可能要花很多时间了!:@)
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-21 17:32 , Processed in 0.059782 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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