缩短我的代码,在matlab中使用冒号运算符

缩短我的代码,在matlab中使用冒号运算符,matlab,colon,Matlab,Colon,我试图找到一种更有效的方法来编写以下代码,旨在将结构的输出放入excel文件中: function output_excel load output structure % convert items from structures to cells, transpose them item1 = struct2cell(item(1,1)); % transforms the 1 entry in the structure to a cell format for excel item

我试图找到一种更有效的方法来编写以下代码,旨在将结构的输出放入excel文件中:

function output_excel

load output structure
% convert items from structures to cells, transpose them

item1 = struct2cell(item(1,1)); % transforms the 1 entry in the structure to a cell format for excel 
item1=item1'; % make out of the item (6x1) a (1x6)

item2 = struct2cell(item(1,2));
item2 = item2';

item3 = struct2cell(item(1,3));
item3 = item3';

item4 = struct2cell(item(1,4));
item4 = item4';

col_header={'Item','ChosenAnswer','ReactionTime','Cue','block'};
xlswrite('Output1',col_header,'A1:E1');
xlswrite('Output1',item1,'A2:E2');
xlswrite('Output1',item2,'A3:E3');
xlswrite('Output1',item3,'A4:E4')
xlswrite('Output1',item4,'A5:E5')

end

输出结构为1x18,因此手动执行此操作将非常无效。我知道有一种方法可以告诉matlab,它应该像我上面描述的那样对结构中的所有18项执行操作。我知道我必须以某种方式使用冒号运算符,但未能正确使用

为什么不简单地为i=1使用
:numel(item)
-循环执行
currentitem=struct2cell(item(i));xlswrite('Output1',currentitem',sprintf('A%d:E%d',i,i))?这很好用!谢谢!现在我只需要让它在第3行(excel)而不是第1行开始,这样我就可以包含列标题和一个时钟!我想这不是一个如何做到这一点的问题。是的,是的,很抱歉不清楚!:)看看
datestr(现在)
。如果您了解我前面的代码的功能,那么从第3行开始应该很容易。