I have 15 columns of different size. I want to write it in a single excel sheet with 15 columns and different row sizes. When I run the following code, I got a message "Conversion to cell from double is not possible". How to resolve this issue?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
data1=xlsread('Gauge-Discharge Data Biligundulu,1971-2012.xlsx');
data2=xlsread('Gauge-Discharge Data K.M.Vadi,1978-2012.xlsx');
data3=xlsread('Gauge-Discharge Data Kanakpura,1979-2003.xlsx');
data4=xlsread('Gauge-Discharge Data Kodumudi,1971-2012.xlsx');
data5=xlsread('Gauge-Discharge Data Kollegal,1971-2012.xlsx');
data6=xlsread('Gauge-Discharge Data Kudige,1973-2011.xlsx');
data7=xlsread('Gauge-Discharge Data M.H. Halli,1977-2012.xlsx');
data8=xlsread('Gauge-Discharge Data Musiri,1971-2012.xlsx');
data9=xlsread('Gauge-Discharge Data Muthankera,1973-2012.xlsx');
data10=xlsread('Gauge-Discharge Data Nalammaranpatti,1977-2011.xlsx');
data11=xlsread('Gauge-Discharge Data Nellithurai,1978-2011.xlsx');
data12=xlsread('Gauge-Discharge Data Savandapur,1977-2012.xlsx');
data13=xlsread('Gauge-Discharge Data T. Narasipur,1971-2012.xlsx');
data14=xlsread('Gauge-Discharge Data T.K. Halli,1978-2012.xlsx');
data15=xlsread('Gauge-Discharge Data Urachikottai,1978-2012.xlsx');
% Storing the data in a single sheet
a1=data1(:,4);
a2=data2(:,4);
a3=data3(:,4);
a4=data4(:,4);
a5=data5(:,4);
a6=data6(:,4);
a7=data7(:,4);
a8=data8(:,4);
a9=data9(:,4);
a10=data10(:,4);
a11=data11(:,4);
a12=data12(:,4);
a13=data13(:,4);
a14=data14(:,4);
a15=data15(:,4);
n=max([length(a1),length(a2),length(a3),length(a4),length(a5),length(a6),length(a7),length(a8),length(a9),length(a10),length(a11),length(a12),length(a13),length(a14),length(a15)]);
R=cell(15052,15);
R(1,1:length(a1))=a1;
R(2,1:length(a2))=a2;
R(3,1:length(a3))=a3;
R(4,1:length(a4))=a4;
R(5,1:length(a5))=a5;
R(6,1:length(a6))=a6;
R(7,1:length(a7))=a7;
R(8,1:length(a8))=a8;
R(9,1:length(a9))=a9;
R(10,1:length(a10))=a10;
R(11,1:length(a11))=a11;
R(12,1:length(a12))=a12;
R(13,1:length(a13))=a13;
R(14,1:length(a14))=a14;
R(15,1:length(a15))=a15;
xlswrite('annualmean.xls',R)
1 comentario
dpb
el 5 de Ag. de 2016
"...write it in a single excel sheet with 15 columns and different row sizes"
NB: The orientation of your array as written will write in rows with different column lengths instead.
Respuestas (2)
dpb
el 4 de Ag. de 2016
Editada: dpb
el 4 de Ag. de 2016
Learn to use arrays (or named structure fields) rather than creating all those named variables
I'd do something more like
d=dir('Gauge-Discharge Data*.xlsx'); % get all the wanted files..
colmn='A'; % initial column; modify as needed
for i=1:length(d) % iterate over the collection
R=xlsread(d(i).name); % get each workbook in turn...
rnge=sprintf('%c:%c',colmn,colmn); % create range expression 'A:A', 'B:B', ...
xlswrite('annualmean.xls',R(:,4),rnge) % and write that column
colmn=colmn+1; % increment column for next iteration
end
NB: Air code; no guarontee against typos or dumb mistakes like mismatched/missing parens, etc., altho did check the string generation for the column...debug as needed and as always "salt to suit" :)
0 comentarios
Walter Roberson
el 4 de Ag. de 2016
R(1,1:length(a1)) = num2cell(a1);
1 comentario
dpb
el 5 de Ag. de 2016
Sidebar note...I just learned xlswrite is cell array enabled; I had presumed that it would be limited to "normal" arrays.
I still think creating a zillion variables instead of a single array is a_bad_idea(tm)_, but could use a cell array to accumulate in previous solution instead of writing each column one-at-a-time.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!