Export Timetable data to Excel
显示 更早的评论
I have a lot of rainfall data which has been uploaded to thingspeak. I want to download some of that data and analyse it in Excel. I was hoping to use the MATLab analysis to do this.
Bearing in mind I am fairly new to this and programming isn't my thing.
I was hoping to use the following code which as far as I understand extracts the data in TimeTable format and then use the writetimetable function to create an Excel spreadsheet. When I run it it extracts the data and displays it as I want without error but I don't know what happens to the xlsx file.
I'm probably missing something
readChannelID = ******;
readAPIKey = '******';
RainFieldID = 1;
RainFall = thingSpeakRead(readChannelID,'Fields',RainFieldID,'NumDays',7,'ReadKey',readAPIKey,OutputFormat='TimeTable');
display(RainFall,'Rainfall');
writetimetable(RainFall,'TT.xlsx')
1 个评论
Stephen23
2024-9-27
Using WRITETIMETABLE is a better approach than converting to table and then using WRITETABLE.
采纳的回答
更多回答(1 个)
Jaimin
2024-9-27
Since I don't have API credentials, I am unable to reproduce the issue. However, I do have a workaround that you might try.
You can convert the “timetable” data to a “table” format using the “timetable2table” function. After that, you can store the table data in an Excel format using the “writetable” function..
Please refer following code snippet for better understanding.
% Convert the timetable to a table
RainFallTable = timetable2table(RainFall);
% Write the table to an Excel file
writetable(RainFallTable, 'TT.xlsx');
Refer following MathWorks documentation for more information on “timetable2table” function
Refer following MathWorks documentation for more information on “writetable” function
I hope this will be helpful.
3 个评论
chris weedon
2024-9-27
Jaimin
2024-9-27
Modify the line from "writetable(RainFallTable,'C:\Users\chris\Downloads\TT.xlsx');" to "writetable(RainFallTable, 'TT.xlsx');". After execution, type the "pwd" command in the Command Window. Navigate to the path displayed as the output, and you will find the "TT.xlsx" file there.
Stephen23
2024-9-27
"Where does the excel file end up??"
In C:\Users\chris\Downloads, if that is the location you told it to use.
类别
在 帮助中心 和 File Exchange 中查找有关 Prepare and Analyze Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!