xlsxwrite is not working. Do I need MS Excel pre-installed to use xlswrite
Show older comments
When I run the following code, I get the error "Existing file C:/Data.......(hereis the folder path) may be open. Please close the file and try again". I have pasted only the last part of the code.
Could someone please suggest how to get the three lines working.
xlsxwrite([FilePath FileName],[PeakLabels;num2cell(PeakData)],1)
xlsxwrite([FilePath FileName],[SeriesLabels;num2cell(SeriesData)],2)
xlsxwrite([FilePath FileName],[SummaryLabels;num2cell(SummaryData)],3)
I do not really need the output as MS Excel file, any other table format including csv or txt is also fine. Do I need MS Excel pre-installed to use xlswrite? I do not have MS Excel installed.
Any feedback will be of great help.
Many thanks!
Here is the code:
% A third sheet brings it ALL together....
SummaryData = zeros(1,8);
SummaryLabels ={'Mean Number of Signal Events', 'Standard Deviation of the Number of Signal Events', 'Mean Height (all)', 'Mean Rise Time (all)', 'Mean Decay Time (all)', 'Mean FWHM (all)', 'Mean InterEvent Interval (all)', 'Mean Frequency (all)'};
SummaryData(1) = mean(SeriesData(:,2));
SummaryData(2) = std(SeriesData(:,2));
SummaryData(3) = SeriesData(:,2)'*SeriesData(:,3)/sum(SeriesData(:,2));
SummaryData(4) = SeriesData(:,2)'*SeriesData(:,4)/sum(SeriesData(:,2));
SummaryData(5) = SeriesData(:,2)'*SeriesData(:,5)/sum(SeriesData(:,2));
SummaryData(6) = SeriesData(:,2)'*SeriesData(:,6)/sum(SeriesData(:,2));
SummaryData(7) = max(SeriesData(:,2)'-1,0)*SeriesData(:,7)/sum(max(SeriesData(:,2)'-1,0));
SummaryData(8) = 1/SummaryData(7);
% Delete the file if it already exists....
if exist([FilePath FileName],'file')
delete([FilePath FileName])
end
% % And write a new file!
try
xlsxwrite([FilePath FileName],[PeakLabels;num2cell(PeakData)],1)
xlsxwrite([FilePath FileName],[SeriesLabels;num2cell(SeriesData)],2)
xlsxwrite([FilePath FileName],[SummaryLabels;num2cell(SummaryData)],3)
catch
fprintf(1, 'Error.\n');
warndlg(['Existing file ' [FilePath FileName] ' may be open. Please close the file and try again.'], 'Predictors
Not Saved')
return
end
end
4 Comments
Jaideep Cherakka Kesavan
on 24 Dec 2022
Walter Roberson
on 24 Dec 2022
you should be using fullfile(FilePath,FileName) instead of [FilePath FileName] to construct the file name. Most of the routes to getting a file path do not promise that the character vector will end in an appropriate directory separator -- in particular, uiputfile() is inconsistent on that point.
Walter Roberson
on 24 Dec 2022
You are using Windows. In Windows, the default is that a file that is open in one process becomes locked for reading and writing by other processes. Programs have to specifically tell Windows that it is okay to share the file for reading or writing. Excel does not do that -- so if a file is open in Excel, then it is not accessible to other processes, even if Excel is just holding it open for days on end "for efficiency".
Jaideep Cherakka Kesavan
on 25 Dec 2022
Accepted Answer
More Answers (1)
Jaideep Cherakka Kesavan
on 26 Dec 2022
0 votes
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!