How to Create a list and save it in a txt file?

4 ビュー (過去 30 日間)
Oliver Bunn
Oliver Bunn 2017 年 3 月 10 日
編集済み: Stephen23 2017 年 3 月 10 日
I am reading data from files in a directory. I am taking the standard deviation of this data. Using an If loop I only plot the Values which are over a certain limit. For Example:
for i=1:(number of files)
x=load(file(i).mat) <---- this isn't how I load it in just example
xx=i;
y=std(x);
if y>0.5
plot(xx,y)
hold on
(Now I want to save the file names which fall in this condition to a .txt file and in the end have a list of each file)
end
end
hold off
figure;
What code can I use to fill the gap in the If loop to save these file names to a list?

採用された回答

ES
ES 2017 年 3 月 10 日
編集済み: Stephen23 2017 年 3 月 10 日
%Open a log file for writing
fID= fopen(logfilename,'w');
..your code...
% Write filename into logfile
fprintf(fID,'%s\r\n',file(i).mat);
%Close logfile
fclose(fID)
  2 件のコメント
Oliver Bunn
Oliver Bunn 2017 年 3 月 10 日
I can't quite work out how to open a log file. I'm using matlab R2011b which doesn't seem to have it.
Stephen23
Stephen23 2017 年 3 月 10 日
編集済み: Stephen23 2017 年 3 月 10 日
@Chocolate Warrior: this time I formatted your code for you. Next time you can do it yourself by selecting the code and then clicking the {} Code button above the textbox.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by