Code to handle excel using Matlab

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 个评论

What is the extension of the files? Do they have no extension? Or is the extension something like ".txt" and the extension is hidden in Windows File Explorer?
Yes it's just text file.
In this video, It is opened by Notepad++
I understand it's a text file, but it's important to know the actual extension.

请先登录,再进行评论。

回答(1 个)

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

类别

帮助中心File Exchange 中查找有关 Data Import from MATLAB 的更多信息

标签

回答:

2023-1-6

Community Treasure Hunt

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

Start Hunting!

Translated by