MATLAB Answers

Matlab writes junk #N/D in Excel file

5 views (last 30 days)
farzad
farzad on 23 Jul 2018
Commented: farzad on 24 Jul 2018
Hi All
I should write an array of 50000x2 from MATLAB to an Excel file, the problem is MATLAB doesn't leave the next rows free and writes something like : #N/D till the line 1 milion !!!
So I should delete it all, but I have so many files
could someone kindly propose a solution ?

  2 Comments

dpb
dpb on 23 Jul 2018
Would have to see the code that seemed to cause the problem and probably have the data as well.
Are you sure the sheet(s) weren't already that way first?
farzad
farzad on 23 Jul 2018
Matlab creates that file, so the files did not exist before even , my part of the code to make the excel file and write the array to that is :
Xsig = [t,Xavp];
xlswrite(name, Xsig, 1, 'A:B');
up, Xavp is a 50,000x1 array, which will be added to Xsig together with time, with the same length, I believe that a random big array will behave the same here

Sign in to comment.

Accepted Answer

OCDER
OCDER on 23 Jul 2018
Edited: OCDER on 23 Jul 2018
Either specify the exact excel range to write to, or don't specify it at all.
Xsig = rand(10, 2);
xlswrite('test.xlsx', Xsig, 1, sprintf('A1:B%d', size(Xsig, 1)));
OR
Xsig = rand(10, 2);
xlswrite('test.xlsx', Xsig, 1);
When you say write to 'A:B', Matlab has an odd behavior to fill EVERY cell in columns A and B with something. Hence, the 1 million rows of N/A's

  4 Comments

Show 1 older comment
farzad
farzad on 23 Jul 2018
Thank you so much, since it is a data acquisition ,I don't know in advance , due to some calculations in the middle, how many points I will have, not I tried with not specifying, just I forgot, what does that 1 mean after Xsig ? Is there a complete documentation guide to deal with Excel and text files in MATLAB ?
OCDER
OCDER on 23 Jul 2018
xlswrite(name, Xsig, 1, 'A:B');
^ sheet number
You could try
doc xlswrite
help xlswrite

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!