A very strange cell array size-relaetd issue

Hi!
I wrote a nice MATLAB program which reads information (numbers) stored in text files. This information is then presented graphically on the screen (as images or plots).
My problem is as follows: Everything works PERFECTLY for very small files (no bigger than 950kb) but not for larger files ???
The segment which performs the file loading, stores the data in a two dimentional (n by 30) array of cells. Each cell is a vector (normally consisting of 100 doubles):
datout = fopen('datout.txt');
i=0;
line = textscan(datout,'%s %d %s %f %s %s %f %s',1);
while ~feof(datout)
i=i+1;
handles.timestep_vector(i)=line{2};
handles.time_vector(i)=line{4};
handles.radius_vector(i)=(3/4/pi*line{7})^(1/3)/100000;
line = textscan(datout,'%s %s %s %s %s %s %s %s %s %s %s %s',1);
handles.A(i,1:11) = textscan(datout,'%*d %f %f %f %f %f %f %f %f %f %f %f',IMX);
line = textscan(datout,'%s %s %s %s %s %s %s %s %s %s %s %s',1);
handles.A(i,12:22)=textscan(datout,'%*d %f %f %f %f %f %f %f %f %f %f %f',IMX);
line = textscan(datout,'%s %s %s %s %s %s %s %s %s',1);
handles.A(i,23:30)=textscan(datout,'%*d %f %f %f %f %f %f %f %f',IMX);
line = textscan(datout,'%s %d %s %f %s %s %f %s',1);
end
fclose(datout);
Again, when using small files my program works impeccabley. When the size of array A is bigger than 21x30, I get the following error. Why?
??? In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in ==> PROG4>PROG4_OpeningFcn at 646 handles.timestep_vector(i)=line{2};
Error in ==> gui_mainfcn at 221 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> PROG4 at 42 gui_mainfcn(gui_State, varargin{:});
The structure of the file DOES NOT change. And the maximum size allowed for an array is in the order of hundreds of MB... What is going on???

 Accepted Answer

dbstop if error
at the command line; then run it with a data set that fails and analyze the sizes of the variables at the assignment. Apparently the size of what you're assigning is different than the size of the location it's going. (A(:) = B error)

2 Comments

Hi Sean.
Your command line has allowed me to debug this problem better. What I am getting for the structure of A is as follows:
1 .. 12 .. 23.. ..30
.
.
19 <100x1 double> <100x1 double> <100x1 double>
20 <100x1 double> <100x1 double> <100x1 double>
21 <100x1 double> .. [] .. <100x1 double> ..
22 <49x1 double> <100x1 double> [] ..
So until the 20'th table in the file, the loop reads everything fine. on the 21'st and the also the 22'nd tables, MATLAB is starting to load the wrong sizes for some of the vectors (less than 100 or even '[]'). I would like to stress that the problem is not with the file. All tables have exactly the same structure, because they are by the exact same code (naturally I also checked visually). To make sure I am not mistaken, I have copy pasted table 19 and 20 (which we know are correct from before), and duplicated them again in the file before 21 and 22. And still, I got the same error on the 21'st and 22'nd tables. This is why I suspected a memory issue problem.
Do you have any idea how to proceed?
Thanks
Uri
I don't suspect a memory problem. Due to the error I suspect a dimension mismatch as the error message implies. Look at Jan's suggestion.

Sign in to comment.

More Answers (1)

Jan
Jan on 11 Oct 2011
If the cell element line{2} is empty, you cannot assign it to handles.timestep_vector(i). I guess that you have an empty line ate the end of the file, or on of the data is missing.

1 Comment

Hi Jan.
Thank you for your quick response. Please see my answer to Sean if you can kindly assist.
Thanks
Uri

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!