MatLab command to replace F9 button in Excel with rand() function
5 次查看(过去 30 天)
显示 更早的评论
I have an excel file generating and elaborating random numbers starting with the rand() function and then applying some other operations. The final column of values changes every time that F9 is pressed. I'm trying to create a MatLab script that reads that column and saves it in a matrix, then "refreshes" the excel sheet with an equivalent command to F9, reads the new column and saves it in a new column in the matlab matrix. This procedure needs to be performed in loop for several times, but I cannot figure out how to refresh the randomly generated numbers in excel with a matlab command. Thanks in advance for your help!
0 个评论
回答(1 个)
Rishi Binda
2018-9-6
编辑:Rishi Binda
2018-9-6
I understand that you want the updated values of the Excel sheet column in your MATLAB Matrix without manually opening the sheet or pressing refresh (F9).
First you can set you workbook to automatically refresh data at regular intervals. Set the Connections Properties in the Data tab and select the Refresh every option. Set the refresh time.
Now you can create a server for Microsoft Excel in MATLAB by using actxserver. This creates an active session of the excel file without opening it. You can read, save and close the file. Here is the link for reference :
You can put the part of the code where it reads the data in a for loop and use pause function to set a wait time equal to your refresh time of the excel sheet. It will run the loop iteration after the sheet is updated and read the data of the updated sheet.
for i=1:100
%code for reading data
pause(%wait time)
end
Here are some links which are on the same thoughts if you require more insights :
Hope this helps!
-Rishi
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!