Finding minimum and maximum in many txt samples.

1 回表示 (過去 30 日間)
Jonasz
Jonasz 2013 年 8 月 6 日
I would like to find min and max in samples which I load from my directory to Matlab. I need to speed up it a little bit and try avoid eg. loops . Is there any easy way how to find min and max in many samples without using 'for' loop? How to read txt files no one by one in a loop but all at once?
Part of my code:
list=dir('*.txt');
for i=1:length(list)
fid=fopen(list(i,1).name);
text_1=cell2mat(textscan(fid,'%f %f'))';
end
fclose(fid);
  1 件のコメント
Matt Kindig
Matt Kindig 2013 年 8 月 6 日
編集済み: Matt Kindig 2013 年 8 月 6 日
One thing that might help is to move the fclose(fid) statement inside the for loop. As it stands now, you are only closing the last file after all *.txt files have been processed. This means that Matlab has to keep each of those file handles open during the loop, which takes up I/O resources.
In other words:
list=dir('*.txt');
for i=1:length(list)
fid=fopen(list(i,1).name);
text_1 = textscan(fid, '%f %f', 'CollectOutput', true));
text_1 = text_1{1}; %this might be a bit faster as well
fclose(fid);
end
Does this help?

サインインしてコメントする。

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 6 日
I do not think, there is a better way to do it without a for loop
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 6 日
[Jonasz commented]
Ok thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by