# Write in Excel With Matlab on continues Cells

4 views (last 30 days)
Virginia on 26 Jun 2013
Hello!, I'm trying to make a code which writes data of a matrix in an Excel Worksheet, however, I'd like to write several matrices one after the other, the problem is that with the function xlswrite I have to specify the cell were the matrix is going to be written, and depends on the data there will be diferents quantities of matrices.
Right now I have this:
fprintf('Select file location \n');
ubic=uigetdir;
name=input('Specify Name of the file: ','s');
comp=strcat(ubic, '\',name, '.xls');
nomhoja='Desplazamiento';
for i=1:np
xlswrite(comp, [rangT',maximox(i,1:num)'], nomhoja, 'A2');
end
As you can see I need to write this matrix [rangT',maximox(i,1:num)'] 'np' times, so when I write 'A1' for the first loop it's fine but for the next one I need it to be 'C1', the next one 'E1'.. etc
Hope You can help me
Thanks!!

Iman Ansari on 26 Jun 2013
First put your data in a cell array then write it:
rangT = 1:10;
maximox = rand(10,10);
fprintf('Select file location \n');
ubic=uigetdir;
name=input('Specify Name of the file: ','s');
comp=strcat(ubic, '\',name, '.xls');
nomhoja='Desplazamiento';
C = cell(10,20);
for i=1:10
C(:,(2*i-1):(2*i)) = num2cell([rangT',maximox(i,1:10)']);
end
xlswrite(comp, Data, nomhoja);
Iman Ansari on 26 Jun 2013
np = 10;
num = 8;
rangT = 1:8;
maximox = rand(10,8);
nomhoja='Desplazamiento';
C=cell(num,2*np);
for i=1:np
C(:,(2*i-1):(2*i)) = num2cell([rangT',maximox(i,1:num)']);
end
xlswrite(comp, Data, nomhoja);