MatLab command to replace F9 button in Excel with rand() function

조회 수: 8 (최근 30일)
Marco Barbaro
Marco Barbaro 2018년 9월 3일
편집: Rishi Binda 2018년 9월 6일
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!

답변 (1개)

Rishi Binda
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by