MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   请帮助我缩短代码 (https://www.labfans.com/bbs/showthread.php?t=23799)

poster 2019-12-10 20:48

请帮助我缩短代码
 
[B]我的问题是缩短重复过程。[/B]
[INDENT][INDENT] Data1 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[31 1 286 255]);

Data2 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[299 1 554 255]);

Data3 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[567 1 822 255]);

Data4 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[835 1 1090 255]);

Data5 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[1103 1 1358 255]);

Data6 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[1371 1 1626 255]);

Data7 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[1639 1 1894 255]);

Data8 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[1907 1 2162 255]);

Data9 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[2175 1 2430 255]);

Data10 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[2443 1 2698 255]);

Data11 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[2711 1 2966 255]);

Data12 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[2979 1 3234 255]);

Data13 = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\ t',[3247 1 3502 255]);

[/INDENT][/INDENT]在获取Data1之前必须跳过前30行。在Data1之后,Data2-Data13必须忽略12行。每个数据包含256 * 255矩阵。

[B]注意:dlmread('myfile.txt','\ t',[R1 C1 R2 C2]);[/B]

您的所有帮助我都会非常感激。谢谢。



[B]回答:[/B]

您可以使用循环并在单元格数组中收集数据集,例如(未经测试)

nData = 13; data = cell(nData,1); for n = 1:nData startPos = 31+(n-1)*268; endPos = 286 + (n-1)*268; data{n} = dlmread('BadgCk-20001103-RZhS-1hAccumx10-TextData0-1.txt','\t', [startPos 1 endPos 255]); end 编辑:如果以后要将所有数据合并到一个大矩阵中,则可以使用

dataMatrix = [data{:}] 您可能需要先转置dlmread的结果,具体取决于您要如何连接到最终矩阵中



[url=https://stackoverflow.com/questions/3519145]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 14:17

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.