Code to handle excel using Matlab

3 ビュー (過去 30 日間)
상호 고
상호 고 2023 年 1 月 6 日
回答済み: Voss 2023 年 1 月 6 日
I want to handle excel using Matlab because there are lots of excel files and handling these manually is quite tedious.
Uploaded link is showing process that I want to repeat by using Matlab but I'm not good at coding and I don't know function for excel in Matlab.
This video is treating excel file whose name is 'Data001' and I want to repeat this process upto 'Data040'
How can I do?
Thank you~!
  3 件のコメント
상호 고
상호 고 2023 年 1 月 6 日
Yes it's just text file.
In this video, It is opened by Notepad++
Voss
Voss 2023 年 1 月 6 日
I understand it's a text file, but it's important to know the actual extension.

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

回答 (1 件)

Voss
Voss 2023 年 1 月 6 日
Try this:
% use the directory where your files are here:
input_file_path = 'C:\2021_11_15\Inlet';
% use the directory where you want the new files to go here:
output_file_path = 'C:\2021_11_15\Inlet_after_handling';
% get info about the relevant files in the input directory
files = dir(fullfile(input_file_path,'Data*.txt')); % if they have .txt extension
% remove any directories returned by dir
% (might happen if the files have no extension):
files([files.isdir]) = [];
% construct full-path file names of input and output files:
input_file_names = fullfile(input_file_path,{files.name});
output_file_names = fullfile(output_file_path,{files.name});
% read each input file and write the corresponding output file:
for ii = 1:numel(files)
A = readmatrix(input_file_names{ii},'FileType','text'); % 'FileType','text' is necessary if the files have no extension
% writing only columns 1,3,2,6,5 in that order
writematrix(A(:,[1 3 2 6 5]),output_file_names{ii},'Delimiter','\t','FileType','text');
end

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by