matlab 2016b xlswrite error ... use to work now does not
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
Vinai Datta Thatiparthi
2020-4-14
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.
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!