Extract a specific row from a struct array?

27 ビュー (過去 30 日間)
Ali Mahdi
Ali Mahdi 2021 年 5 月 5 日
コメント済み: Ali Mahdi 2021 年 5 月 10 日
Hello everyone,
I have a bunch of excel file and I would like to extract a specific row from each file. I used the following code, but I couldn't export a specific row (let's assume the 2nd row from each file) to a new excel file.
clear all; clc
% we can use uigetfile for load multiple files
[file_list, path_n] = uigetfile('.csv', 'MultiSelect','on');
x=length(file_list);
for i=1:x
filename=file_list{i};
data_in.file_list{i}=readtable(filename);
Output.file{i}=data_in.file_list{i}(:,[ 2 5 6 9 10 11 12]);
end
for i=1:x
table{i}=Output.file{i}
disp('------------------------------')
end
% for i=1:x
% table{1, i}
% disp('----------------------')
% end

回答 (1 件)

Divya Gaddipati
Divya Gaddipati 2021 年 5 月 10 日
If you want the 2nd row from each file, you can modify the code like:
for i = 1:x
table{i} = Output.file{i}(2,:);
disp('------------------------------')
end
  1 件のコメント
Ali Mahdi
Ali Mahdi 2021 年 5 月 10 日
Dear Divya,
Thank you for your reply.
Ok, I got 2nd row form each excel file. How can I export these data into one excel file (i.e. one excel file contain the 2nd row of each excel file).
your helping is highly apprciated
Thank you in advance
Regards

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by