input Matlab table columns to excel formula and perform iteration calculation
29 ビュー (過去 30 日間)
古いコメントを表示
I have two matlab tables called meandiretcion (image1) and meanspeed (image2). I also have a excel file with formula (image3), the excel formula file has 3 sheet (sheet1, sheet2, sheet3).
The aim is to perform iterative calculation on excel formula file using the value from two matlab tables.
For example, column1 of meandirection will be input to sheet1.columnF, column1 of meanspeed will be input to sheet2.columnM, results from sheet 3.columnP will be saved.
And then column2 of meandirection will be input to sheet1.columnF, column2 of meanspeed will be input to sheet2.columnM, results from sheet 3.columnP will be saved.
And then column3 of meandirection will be input to sheet1.columnF, column3 of meanspeed will be input to sheet2.columnM, results from sheet 3.columnP will be saved...
How do I perform this automatic task with Matlab?



2 件のコメント
dpb
2025 年 1 月 31 日 18:55
This is a very inefficient approach; much better would be to read the data and do the calculation in MATLAB and then write all the results. The approach above would have to open/close all three files for every column instead of just once for reading/computing and once to output results.
My experience has been that trying to use readtable/writetable or related cell/matrix routines in such a tight loop can fail with the system eventually hanging as the Excel COM processes are created and closed and timing issues arise. If one were to really attempt the above in a loop, my recommendation would be to open a COM session and then do it all there before closing the output file. One could still read the two input files in one call to each file and have the data in memory for the calculations. There's really no point in updating the Excel workbook for every call; as described it will just end up with the last set in place; bring the calculation over to MATLAB and one could use vectorized operations and most likely avoid loops altogether.
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!