我在 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');
最佳答案
我猜您想要代码中定义的函数 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;
关于excel - 如何将matlab答案导出到excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583932/