memory problem
Show older comments
The matlab code below was used to search the contents of File2 with the contents of file1, and with the example output below. However, when large files are involved, the output is reduced.
File1:
M1U152S44906X14127_xu
M1U7S112336U117688_xu
File2 (tab delimited):
T1X19S17508N179711_xu AAU_779
M1U152S44906X14127_xu xcup
M1U7S112336U117688_xu mmna
Expected output:
M1U152S44906X14127_xu xcup
M1U7S112336U117688_xu mmna
Code:
clear all;
clc;
%Open flux file for reading
fid = fopen('File2.txt')
if fid ==-1
disp('Reaction_Flux file open not successful')
else
% Read characters and numbers into separate elements
% in a cell array
rxn_flux = [];
A = [];
B = [];
C = [];
rxn_flux = textscan(fid,'%d %s %s');
A = rxn_flux{1};
B = rxn_flux{2};
C = rxn_flux{3};
len1 = length(B);
closeresult1 = fclose(fid);
if closeresult1 == 0
disp('Reaction_Flux file close successful')
else
disp('Reaction_Flux file close not successful')
end
end
%Open reaction file for reading
fid = fopen('File1.txt')
if fid ==-1
disp('Flux file open not successful')
else
% Read characters and numbers into separate elements
% in a cell array
[rxn] = textread('File1.txt','%s');
%rxn = textscan(fid,'%s');
D = rxn;
len2 = length(D);
closeresult2 = fclose(fid);
if closeresult2 == 0
disp('Reaction file close successful')
else
disp('Reaction file close not successful')
end
end
%Open output file for writing results
fid = fopen('OutputFile.txt','w');
fprintf(fid,'The following were found in File 1:\n')
RXNFLUX = false(size(B));
for i = 1:len2
RXNFLUX = RXNFLUX | strcmpi(D{i},B);
end
if any(RXNFLUX)
iLines = [];
iLines = find(RXNFLUX);
for i=1:size(iLines)
fprintf(fid,'%s\t, %s\n',B{iLines(i)}, C{iLines(i)});
% B{iLines(i)} and C{iLines(i)}
%fprintf(fid,'%s\t, %s\n', B, C);
%fprintf(fid, '%s\n', B{:});
%dlmwrite('output.txt',B(iLines(i)),'\n');
end
else
disp('rxn not found')
end
fclose(fid);
I will be happy to get some help to resolve the problem.
Thanks
2 Comments
per isakson
on 6 Jun 2012
Does the full content of File1 and File2 fit i memory at the same time? How large are they?
Jason Ross
on 6 Jun 2012
Can you add:
Operating system
32 bit vs. 64 bit
Amount of RAM in your system
Version of MATLAB
Amount of free memory at start (e.g. run the "memory" command)
Answers (0)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!