How can i edit data in multiple text files?

5 ビュー (過去 30 日間)
Bruno Carvalho
Bruno Carvalho 2021 年 3 月 23 日
コメント済み: Jan 2021 年 3 月 24 日
I have hundreds of .txt files of data, and i need to order that data, and save only the top and bottom 10% of it to the same .txt file.
I've looked arround and tryed some things out but with no luck so far.
This is what i have.
clear all
close all
clc
Folder = 'C:\Users\Bruno\Desktop\teste123';
FilePattern = fullfile(Folder, '*.txt');
TheFiles = dir(FilePattern);
for k = 1 : length(TheFiles)
BaseFileName = TheFiles(k).name;
FullFileName = fullfile(TheFiles(k).folder, BaseFileName);
Data = readmatrix(BaseFileName);
SortedData = sortrows (Data,-5);
RowsToDelete = [11:83];
SortedData(RowsToDelete,:) = [];
HighCorr = SortedData(1:10,:);
LowCorr = SortedData(11:20,:);
end
With this script, matlab only gives me the top and bottom 10% (named HighCorr and LowCorr) of the first file.
I need to save this in the respective .txt file, and do the same with the rest of my folder.
Can someone help please?
  11 件のコメント
Bruno Carvalho
Bruno Carvalho 2021 年 3 月 24 日
Yes, thats perfect. Thank you very much.
Jan
Jan 2021 年 3 月 24 日
Then I will repost it as an answer.

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

採用された回答

Jan
Jan 2021 年 3 月 24 日
SortedData = sortrows (Data, -5);
n = size(SortedData, 1);
Data = SortedData([1:10, 84:s], :);
writematrix(FullFileName, Data);

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by