My variable doesn't show up in my workspace and then Matlab stalls?

I'm trying to read a relatively large csv (15,0000 x 2000) table into MATLAB. I've functionalized a loop to read the code using textscan:
% Opens the files using the fID.
fID = fopen(filename);
% Uses textscan to read in the file using the carriage return as a delimiter.
Lines = textscan(fID,'%s','delimiter', {'\n','\r'});
Lines = Lines{1,1};
% Determines the number of lines and ignores the first line, which is a single
% string.
linesize = size(Lines,1)-1;
% Uses a comma/tab delimiter to separate first line
Line = Lines{2,1};
Row = textscan(Line,'%s','delimiter',',\t');
Row = Row{1,1};
dataout = Row';
% Separates subsequent lines
for ind = 3:linesize
Row = textscan(Lines{ind,1},'%s','delimiter',',\t');
Row=Row{1,1};
dataout(ind-1,:)=Row';
end
When my function returns to the commandline, the output variables from the function do not appear in the Workspace terminal. When I call "Who", they are listed there. When I try to open a variable (any variable) in the command line, the program sits "busy" for several minutes until I get fed up with waiting for Matlab to print the variable output and terminate the code.
I know my problem isn't associated with using the avaliable memory, as I've tried this before on other occasions and it either generates an error report or it prints back to the command line that memory has been exceeded.
I'm wondering if anyone has had a similar problem, and how it was handled.
Thanks!

3 Comments

What exactly is the problem? The function runs fine, but the display of the results in the command window takes longer than you want? But why do you want to display 30'000'000 elements in the command window or workspace browser? Or are there any problems with the function?
There is no problem with the code. It runs fine with a smaller matrix. But, when I execute this as a function, I have the function print a message after the code runs. I get the code and am able to run things in the command line. My output variable doesn't show in the workspace. When I call "Who" the variables are printed. When I call my next variable or function from the command line, Matlab basically freezes and it takes 10 or 15 minutes to print a string or empty set from the workspace.
I'd like to understand (1) Why my variables don't show up in the workspace and (2) why my computer stalls on really basic commands which should normally run.
If you close and reopen the workspace does it show up?

Sign in to comment.

Answers (1)

It was not your problem, but I guess this is faster:
fID = fopen(filename);
Line1 = fgetl(fID);
Row = textscan(Line1, '%s', 'delimiter', ',\t');
nCol = numel(Row{1});
fseek(fID, 0, -1);
data = fscanf(fID, '%g, ', [nCol, inf]);
fclose(fID);
Or perhaps this, when there is no trailing comma in each line:
fmt = repmat('%g, ', 1, nCol);
fmt(end-1:end) = [];
data = fscanf(fID, fmt, [nCol, inf]);
And finally transpose the data on demand.

Categories

Asked:

on 7 Mar 2013

Community Treasure Hunt

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

Start Hunting!