matlab 2016b xlswrite error ... use to work now does not

6 views (last 30 days)
Yesteday the following was working but today it is not and get the following error
The specified data range is invalid or too large to write to the specified file format.
Try writing to an XLSX file and use Excel A1 notation for the range argument, for
example, ‘A1:D4’.
Below is the code ... it seem to be choking on teh way I set up the range "xlrange=strcat('A',num2str(row),':S',num2str(row)) ;" ?
What am I doing wrong?
for i = 1: length(Gain_mean)
% row = findLastRow(filedir,1);
j=j+1;
Data= [ str2double(sn(i,:)), (type(:,i)), str2double(port(j,2:3)),round(Gain_mean(i)*100)/100, round(100*Gain_std(i))/100, round(100*Gain_min(i))/100,...
round(100*Gain_max(i))/100, round(100*IRLmean(i))/100, round(100*IRLstd(i))/100, round(100*IRLmin(i))/100,round(100*IRLmax(i))/100, ...
round(100*ORLmean(i))/100, round(100*ORLstd(i))/100, round(100*ORLmin(i))/100, round(100*ORLmax(i))/100, round(100*BW1db(i))/100, ...
round(100*BW3db(i))/100, round(100*BW10db(i))/100, round(100*ripple(i))/100];
Data2=[ Gtype(i) , Gain_mean_1670(i), Gain_mean_1691p25(i),Gain_mean_1705(i), Gain_mean_1712p5(i), ...
Gain_mean_1733p75(i), Gain_mean_1755(i) ] ;
j=j+1;
Data3= [str2double(sn(i,:)), (type(:,i)), str2double(port(j,2:3)), Gain2_mean(i), Gain2_std(i), Gain2_min(i), Gain2_max(i), IRL2mean(i), IRL2std(i),IRL2min(i),IRL2max(i), ...
ORL2mean(i), ORL2std(i), ORL2min(i), ORL2max(i), BW1db2(i), BW3db2(i), BW10db2(i), ripple2(i)];
Data4=[ Gtype(i) , Gain2_mean_1670(i), Gain2_mean_1691p25(i),Gain2_mean_1705(i), Gain2_mean_1712p5(i), ...
Gain2_mean_1733p75(i), Gain2_mean_1755(i) ] ;
xlrange=strcat('A',num2str(row),':S',num2str(row)) ;
xlrange2=strcat('t',num2str(row),':z',num2str(row)) ; row=row+1;
xlrange3=strcat('a',num2str(row),':s',num2str(row)) ;
xlrange4=strcat('t',num2str(row),':z',num2str(row)) ; row=row+1;
try
xlswrite(filedir,Data,1,xlrange) ;
xlswrite(filedir,Data2,1,xlrange2) ;
xlswrite(filedir,Data3,1,xlrange3) ;
xlswrite(filedir,Data4,1,xlrange4) ;
stopp =0;
catch ME
message='Excel Sheet is Open ... close it and RERUN the program' ;
% amp=3 ; fs=10500; % sampling frequency
% freq=3000; duration=.5; values=0:1/fs:duration;
% a=amp*cos(2*pi* freq*values); sound(a)
% errordlg(message) ; stopp =1 ;
return
end

Answers (3)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 14 Apr 2020
Hello Jeffrey,
It appears that the possible reason for the error is not mentioning the format of the Excel file while using xlswrite function. When using the xlswrite function, do mention an ".xlsb", ".xlsx" or ".xlsm" extension for the file when you need to write a large number of rows or columns to Excel. Ensure that the filedir variable contains any of the aforementioned extensions.
In the older ".xls" file format, such a large number of columns was not valid yet. Also, note that if you specify any other file extension, or an incorrect file extension, MATLAB will fall back to the old ".xls" format. I also found a similar MATLAB Answers page here.
Finally, consider using the function writetable over xlswrite (not recommended).
Hope this helps!

Jeffrey Schlang
Jeffrey Schlang on 16 Apr 2020
hmmm ... i created a new xlsx file and it wrote perfectly
Is there a limitation on the number of rows and columns that matlab can write too?

Jeffrey Schlang
Jeffrey Schlang on 4 May 2020
Error using xlswrite (line 219)
The specified data range is invalid or too large to write to the specified file format.
Try writing to an XLSX file and use Excel A1 notation for the range argument, for
example, ‘A1:D4’.
i get this error when the line count gets to about 90
I have 29 columns and 89 rows or 2581 cells

Products


Release

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!