フィルターのクリア

How can I increase the speed of this loop?

1 回表示 (過去 30 日間)
Ash Ahamed
Ash Ahamed 2019 年 10 月 18 日
コメント済み: Ash Ahamed 2019 年 10 月 18 日
This loop takes a long time to finish. Is there anyway I can increase the speed? Thanks
for n=0:5039
name = sprintf('%d/conformability.txt', n)
fid = fopen(name) ;
data = textscan(fid,'%f32','HeaderLines',1) ;
data = cell2mat(data)
n = length(data)
data = reshape(data,[10,n/10])
data = transpose(data)
fclose(fid);
comformability(:,n)=data(:,2)
data = []
end

採用された回答

Jeremy Hughes
Jeremy Hughes 2019 年 10 月 18 日
編集済み: Jeremy Hughes 2019 年 10 月 18 日
It's hard to say without looking at the contents of the file's you're reading.
You're overriding n in the for loop with n as the length of the data. Is that a typo?
% With some assumption about the file you're reading...
fmt = repmat({'%*f32'},1,10);
fmt{2} = '%f32';
fmt = [fmt{:}];
for K=0:5039
name = sprintf('%d/conformability.txt', K);
fid = fopen(name);
data = textscan(fid,fmt,'HeaderLines',1);
fclose(fid);
comformability(:,K+1)=data{1}; % if K == 0 this would error.
end
  3 件のコメント
Jeremy Hughes
Jeremy Hughes 2019 年 10 月 18 日
I also made a typo... My "n" in the sprintf line should be "K"
Ash Ahamed
Ash Ahamed 2019 年 10 月 18 日
Saw that! haha thanks and it worked!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by