Export .mat data into excel file
12 ビュー (過去 30 日間)
古いコメントを表示
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.


0 件のコメント
回答 (1 件)
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'))
0 件のコメント
参考
カテゴリ
Help Center および File 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!