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 CenterFile Exchange 中查找有关 Workspace 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