MATLAB to excel to MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I'm trying to write an input into an excel file which will then calculate the the values I want and then read the values of the excel sheet back into matlab. I keep getting NaN for the outputs of the excel sheet and was wondering what I would need to do in order to obtain the values I want.
Code
filename = 'test3.xlsx';
Den = {'=PropsSI("Dmass","T",850,"P",10000000,"HEOS::CarbonDioxide")'};
HeC = {'=PropsSI("C","T",850,"P",10000000,"HEOS::CarbonDioxide") '};
vis = {'=PropsSI("V","T",850,"P",10000000,"HEOS::CarbonDioxide") '};
xlswrite('test3.xlsx',Den,1,'B2')
xlswrite('test3.xlsx',HeC,1, 'B3')
xlswrite('test3.xlsx',vis,1,'B4')
values = xlsread('test3.xlsx');
댓글 수: 0
답변 (1개)
Roofus Milton
2019년 11월 4일
편집: Roofus Milton
2019년 11월 4일
Hi Jarod-
I do not have the add-in which defines the formula PropsSI. I have provided a generic way to pass data to and return data from Excel. I suspect the error in your approach is the result of the file never being opened. The commented lines with your formulas should replace my formulas.
try
%% Get the Excel Application
try
% Try to attach to an open Excel application
excel = actxGetRunningServer('Excel.Application');
catch exception
% Create the COM object
excel = actxserver('Excel.Application');
end
%% Get the workbook and the worksheet
% Ensure the object is visible
excel.Visible = true;
% If there are no open workbooks then add one to the collection
wb = excel.Workbooks.Add();
% Get the active worksheet in the active workbook
ws = wb.ActiveSheet;
ws.Range("A1").Value2 = 'From MATLAB';
ws.Range("A2").Formula = '=10';
ws.Range("A3").Formula = '=11';
ws.Range("A4").Formula = '=12';
%ws.Range("A2").Formula = '=PropsSI("Dmass","T",850,"P",10000000,"HEOS::CarbonDioxide")';
%ws.Range("A3").Formula = '=PropsSI("C","T",850,"P",10000000,"HEOS::CarbonDioxide")';
%ws.Range("A4").Formula = '=PropsSI("V","T",850,"P",10000000,"HEOS::CarbonDioxide")';
output = cell(3, 1);
output{1, 1} = ws.Range("A2").Value2;
output{2, 1} = ws.Range("A3").Value2;
output{3, 1} = ws.Range("A4").Value2;
catch exception
rethrow(exception)
end
댓글 수: 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!