Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab Preserves Data in Memory, Even After I run ‘clearvars’

Subject: Matlab Preserves Data in Memory, Even After I run ‘clearvars’

From: Ryan

Date: 5 Dec, 2012 14:54:08

Message: 1 of 2

So, I run this code:
d = dir('C:\Users\Excel\Desktop\Excel_Files\*.xls*');
nfiles = length(d);
for k = 1:nfiles
   n=int2str(k);
   eval(['[num' n ', txt' n ', raw' n '] = xlsread(d(k).name,1);']);
end

Everything imports fine. However, if I change some data, and re-run the code, I get what I had initially, NOT the changed data. So, I run ‘clearvars’, and try again; I get the initial data. Then, I deleted ALL Excel files in the folder and run the code. I get 0; this is what I’d expect. However, if I create a new Excel file, and name it Book1, and put it in that same folder as before, I get what was in the FIRST Book1, not the ACTUAL/NEW Book1. This makes no sense whatsoever. It's like Matlab preserves things in it's memory, even after I run 'clearvars'. It can't be like that. There’s no practical application for that kind of thing.

Subject: Matlab Preserves Data in Mem

From: Steven_Lord

Date: 5 Dec, 2012 17:52:28

Message: 2 of 2



"Ryan " <ryanshuell@gmail.com> wrote in message
news:k9nn6g$6ub$1@newscl01ah.mathworks.com...
> So, I run this code:
> d = dir('C:\Users\Excel\Desktop\Excel_Files\*.xls*'); nfiles = length(d);
> for k = 1:nfiles
> n=int2str(k);
> eval(['[num' n ', txt' n ', raw' n '] = xlsread(d(k).name,1);']);

Don't do this! See question 6 in the Programming section of the newsgroup
FAQ instead!

http://matlab.wikia.com/wiki/FAQ

> end
>
> Everything imports fine. However, if I change some data, and re-run the
> code, I get what I had initially, NOT the changed data. So, I run
> clearvars, and try again; I get the initial data. Then, I deleted ALL
> Excel files in the folder and run the code. I get 0; this is what Id
> expect. However, if I create a new Excel file, and name it Book1, and put
> it in that same folder as before, I get what was in the FIRST Book1, not
> the ACTUAL/NEW Book1. This makes no sense whatsoever. It's like Matlab
> preserves things in it's memory, even after I run 'clearvars'. It can't
> be like that. Theres no practical application for that kind of thing.

MATLAB should not be doing what you describe, so there's some information
about what you're doing that you haven't stated. Tell the group the EXACT
procedure you follow to reproduce this problem or send that exact procedure
to Technical Support. Readers or support staff that don't have your data
files should be able to use this procedure to try to reproduce the problem
themselves.

Some suggestions for information to include in your procedure:

1) State the exact contents of the Excel file. When you make a change,
describe exactly the change you make.
2) Following any modification to the Excel file, make sure you SAVE to
ensure the changes you're trying to read have been committed to disk.
3) Try using a different location on disk. In particular, I'm not sure if
Windows handles the Desktop directory specially; try using the temp
directory and see if you can still reproduce the behavior.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us