【发布时间】:2014-06-23 19:49:05
【问题描述】:
我用 matlab 创建了一个 GUI,最后用户可以选择保存数据并将其保存到他们选择的 excel 文件中。
有两组单独的数据保存并写入 excel 文件。第一个是一个数值IntensityValue2,例如4592.25和OtherAUC2,这是一个不同数值的数组,例如[] [5025.8] [5012.3] [4963.45]
这是我正在使用的代码:
% --- Executes on button press in Save.
function Save_Callback(hObject, eventdata, handles)
% hObject handle to Save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
IntensityValue = getappdata(0,'IV');
[FileName,PathName]= uigetfile('*.xlsx*','File to save to');
intensityfile = fullfile(PathName,FileName);
filename = intensityfile;
mypeak = {'Peak(nm)'};
xlswrite(filename,mypeak,'Sheet1','A1');
myintensity = {'Intensity'};
xlswrite(filename,myintensity,'Sheet1','B1');
IntensityValue2 = str2num(IntensityValue);
xlswrite(filename,IntensityValue2,'Sheet1','B2');
OtherAUC = getappdata(0,'AUC')
numfiles = getappdata(0,'files');
for a = 2:numfiles
OtherAUC2{a} = OtherAUC{a}
end
xlswrite(filename,OtherAUC2,'Sheet1','B3');
目前excel文件看起来像这样:
Peak(nm) Intensity
4592.25
5025.8 5012.3 4963.45
而我希望它看起来像这样:
Peak(nm) Intensity
4592.25
5025.8
5012.3
4963.45
谁能帮我实现这个目标?我意识到OtherAUC2 中的第一个单元格是空的,但我认为 foror 循环意味着第一个单元格没有写入 excel 文件。任何帮助或建议将不胜感激!
【问题讨论】:
-
对于方向,转置
OtherAUC2应该可以解决问题 (OtherAUC2.')。指定确切的单元格范围也应该有效,但不够灵活。对于空白单元格,whos与OtherAUC和OtherAUC2的结果是什么? -
@excaza 谢谢我会尝试转置
OtherAUC2。其他AUC 的whos 的结果是Name: OtherAUC Size: 1x4 Bytes:368 Class:cell Attributes:,OtherAUC2 的结果是Name: OtherAUC2 Size: 1x4 Bytes:368 Class:cell Attributes: -
哦,呃,我第一次看时错过了。使用
OtherAUC2{a-1} = OtherAUC{a} -
@excaza 非常感谢!
标签: matlab user-interface xls