xlsread doesn't recognize file has changed

I have a .xlsx file that I read with xlsread. However, if I change the file and call it with xlsread again, it returns the old values. I've tried clear all, clear('myfile.xlsx'), pack, fclose all, but nothing seems to make the xlsread read the newly modified file, except for restarting matlab. How can I force it to read in the new file? And yes, I have saved the new file.(using 2015asp1)

댓글 수: 3

dpb
dpb 2016년 1월 18일
편집: dpb 2016년 1월 18일
>> B=xlsread('B.xls')
B =
36.3027 51.2517
36.2643 51.2544
36.2613 51.2665
>> B1=B(1); % save old value to later restore
>> B(1)=pi
B =
3.1416 51.2517
36.2643 51.2544
36.2613 51.2665
>> xlswrite('B.xls',B) % write the modified back
>> clear B % ensure isn't cached value in memory...
>> B=xlsread('B.xls') % and see what happens...
B =
3.1416 51.2517
36.2643 51.2544
36.2613 51.2665
>> B(1)=B1;
>> xlswrite('B.xls',B)
>> xlsread('B.xls')
ans =
36.3027 51.2517
36.2643 51.2544
36.2613 51.2665
>>
If can't reproduce the above test or something very similar, submit the test results to TMW official support at www.mathworks.com
Above is from R2012b here but I'd surely expect same result from later revisions, too...
ADDENDUM
I also went and manually changed the spreadsheet and Save'd if from within Excel and read it after each change -- first for the first cell modified from initial value to '=pid()' and then restored the initial value. As expected, the results were --
>> % Modify in Excel and read...
>> xlsread('B.xls')
ans =
3.1416 51.2517
36.2643 51.2544
36.2613 51.2665
>> % Put numeric value back, save and re-read...
>> xlsread('B.xls')
ans =
36.3027 51.2517
36.2643 51.2544
36.2613 51.2665
>>
Seems fine here.
It looks like it may have been a problem with excel, because after I saved the file then closed it, I reopened it and it had the old data again -- not the recently "saved" data. I edited again and now it seems to be behaving. properly.
dpb
dpb 2016년 1월 18일
Ah so...I've had some "issues" with Excel, too, so wouldn't surprise me. Perhaps there was another session that hadn't closed properly and was holding the file handle or the like...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

태그

질문:

2016년 1월 18일

댓글:

dpb
2016년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by