Export .mat data into excel file

12 visualizaciones (últimos 30 días)
Shubham Kalode
Shubham Kalode el 3 de Dic. de 2020
Respondida: Kanishk el 29 de En. de 2025
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.

Respuestas (1)

Kanishk
Kanishk el 29 de En. de 2025
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'))

Categorías

Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by