How can I pass a variable from MATLAB to Excel using DDE by passing only the first cell of the Excel sheet?

조회 수: 3 (최근 30일)
How can I pass a variable from MATLAB to Excel using DDE by passing only the first cell of the Excel sheet?
I would like to do something like this:
channel = ddeinit('excel', 'sheet1');
data = rand(5);
range = 'r1c1' % I do not know the end row and column of data
rc = ddepoke(channel, range, data) % This will only populate one cell not the whole data into Excel

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 10월 11일
편집: MathWorks Support Team 2021년 10월 14일
There is no direct API available to do this. You can write a small function to achieve your goal. For example:
function rc = ddepokeUnlimited(channel, startRow, startCol, data)
% This function will take in the startRow number and start Column
% number and write the data provided to the channel using DDE. This
% function will calculate the size range internally
[m n] = size(data);
endRow = startRow + m -1;
endCol = startCol + n -1;
range = ['r' num2str(startRow) 'c' num2str(starCol)...
':r' num2str(endRow) 'c' num2str(endCol) ];
rc = ddepoke(channel, range, data);
Note that MATLAB supports ActiveX protocol. You can use MATLAB as an ActiveX server or as an ActiveX client. You have more functionality available via ActiveX as compared to DDE. Please refer to Chapter 7 of the External Interfaces Users Guide for more information. You can view the HTML format of this section at the following URL:
https://www.mathworks.com/help/matlab/matlab_external/supported-client-server-configurations.html

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by