Divide a column of a datafile through a constant value

1 回表示 (過去 30 日間)
Shivu
Shivu 2022 年 5 月 23 日
コメント済み: Shivu 2022 年 5 月 23 日
I have a large number of datafiles (.txt file) and I need to divide one of the columns to a constant number. What is the short way to do it.
  3 件のコメント
Shivu
Shivu 2022 年 5 月 23 日
Around 70 files having 40 columns each.
Shivu
Shivu 2022 年 5 月 23 日
a = textread('den_T50.txt');
a1 = a(:,1)/0.15;
save ('den_T50.txt','-ascii')
type('Nden_T50.txt')
I have tried this way for a single file. Is there can be any short method for saving a large number of files other than this?
And further, the problem is on saving the new data file (according to above code) it's just appending the modified data column into the previous data. Whereas I want to replace the previous column with the new calculated one.

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

回答 (1 件)

KSSV
KSSV 2022 年 5 月 23 日
txtFiles = dir('*.txt') ; % you are in the folder of text files
N = length(txtFiles) ; % total files
% loop for each file
for i = 1:N
txtFile = txtFiles(i).name ;
T = readtable(txtFile) ; % also have a look on load, importdata
T.(1) = T.(1)/100 ; % divide first column by 100
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by