Export .mat data into excel file

12 ビュー (過去 30 日間)
Shubham Kalode
Shubham Kalode 2020 年 12 月 3 日
回答済み: Kanishk 2025 年 1 月 29 日
Hi,
I have .mat file which contains data like the picture below. If I open one of these data I can see variable and its values(last image). I want to search for some variables by their name in this .mat file and then exract the data into an excel sheet. Any help in exporting the .mat data into an excel file is appreciated.

回答 (1 件)

Kanishk
Kanishk 2025 年 1 月 29 日
The data you have is a "cell array" of "timetable" data. You can search for a variable by its name using a MATLAB Script to iterate through the "call array". To save the data to excel file, "writetable" function can be used.
Here is a simple code which searches for a variable name and saves the "timetable" data in different sheets of excel file.
searchColumnName = 'Var2';
matchingTimetables = {};
for i = 1:length(timetables)
currentTimetable = timetables{i};
if any(strcmp(currentTimetable.Properties.VariableNames, searchColumnName))
matchingTimetables{end+1} = currentTimetable;
end
end
if ~isempty(matchingTimetables)
filename = 'MatchingTimetables.xlsx';
for j = 1:length(matchingTimetables)
sheetName = ['Timetable' num2str(j)];
writetable(timetable2table(matchingTimetables{j}), filename, 'Sheet', sheetName);
end
disp(['Matching timetables exported to ', filename]);
else
disp('No timetables found with the specified column name.');
end
You can learn more about "timetable" and "writetable" by using the following commands in MATLAB to access the documentation.
web(fullfile(docroot, 'matlab/ref/timetable.html'))
web(fullfile(docroot, 'matlab/ref/writetable.html'))

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by