xlswrite() problem with writing file
21 views (last 30 days)
Show older comments
function [ A ] = SaveFile( B )
A=[];
for i=1:size(B,1)
if sum(B(i,:))>10
A=[A;B(i,:)];
end
end
notepad=[pwd '\asd.txt']; %no problem in saving
excellZad=[pwd ' \asdexcel.xlsx' ];
save (notepad, 'A','-ASCII');
xlswrite (excellZad, A);
end
B=[1 2 3; 4 5 6; 7 8 9;10 11 12; 13 14 15; 16 17 18];
SaveFile(B);
This is the error
Error using xlswrite (line 219)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Microsoft Excel cannot access the file 'C:\Users\Lozanovski\Documents\MATLAB \'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Help File: xlmain11.chm
Help Context ID: 0
Error in SaveFile (line 11)
xlswrite (excellZad, A)
Error in main2 (line 3)
SaveFile(B);
Thanks.
0 Comments
Answers (1)
Image Analyst
on 24 Nov 2014
You have a space in the folder that you probably don't want:
excellZad=[pwd ' \asdexcel.xlsx' ]; % Space before the \
Instead, try fullfile():
excellZad = fullfile(pwd, '\asdexcel.xlsx');
Also make sure that some old version of the file is not already open in Excel when you call xlswrite().
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!