如何将exlab的matlab答案导出?

时间:2011-12-21 00:59:17

标签: excel matlab automation

我在Matlab中制作了简单的计算器GUI。如何在MATLAB中将每个答案导出到Excel?请帮助我..我已经使用过xlswrite但它只会替换excel中的答案..你能帮我一个代码,将每个答案输出到excel,这是继续添加答案

代码示例:

a = get(handles.input1_gamma,'String'); %gamma 
b = get(handles.input2_h,'String'); %h 
c = get(handles.input3_q,'String'); %q 
d = get(handles.input4_power,'String'); %POWER 
% a and b are variables of Strings type, and need to be converted 
% to variables of Number type before they can be added together 
out = [str2num(a) * str2num(b)* str2num(c)]; 
e = {'Power','gamma','H','Q'; out,str2num(a),str2num(b),str2num(c)}; 
xlswrite('results.xls', e, 'Sheet1' , 'A1');

2 个答案:

答案 0 :(得分:0)

我想你想要一个代码xlswrite中定义的功能('results.xls',e,'Sheet1','A1');

来自德国的Frohe Weihnachten

另见:

http://www.mathworks.de/de/help/matlab/ref/xlswrite.html

我的建议:

function [ output_args ] = xlswrite( file , e , sheet,range)
%XLSWRITE Summary of this function goes here
%   Detailed explanation goes here


%open excel file with absolute path
file =[cd '\' file];
exlObject = actxserver('Excel.Application');
exlObject.visible = 1;
exlObject.Workbooks.Open(file);
exlWkbk = exlObject.Workbooks;

%save e to defined range
exlSheet1=exlObject.Sheets.Item(sheet);
dat_range=[range ':' range];
rngObj = exlSheet1.Range(dat_range);
rngObj.Value=e;

%save and close
exlObject.DisplayAlerts=0;
exlSheet1.SaveAs(file);
exlWkbk.Close;
exlObject.Quit;

答案 1 :(得分:0)

您可以使用xlsappend上的xlsappend将您的函数输出导出到Excel。

[success,message] = xlsappend(file,data,sheet) 将通过检测Excel工作表的第一个未使用的行来附加数据,并粘贴数字(或单元格)数组。

{{1}}