indices and values
이전 댓글 표시
HI,
If I have this txt file(indices and values),and need read it into array without using for loop. Is there command do that?
(1,2) 3
(2,3) 4
thanks
답변 (3개)
Walter Roberson
2011년 11월 22일
textscan(fid, '%*c%f%*c%f%*c%f')
댓글 수: 6
Walter Roberson
2011년 11월 22일
c = textscan(fid, '%*c%f%*c%f%*c%f');
sparse(c{1},c{2},c{3})
Walter Roberson
2011년 11월 22일
c = textscan(fid, '%*c%f%*c%f%*c%f');
accumarray([c{1},c{2}], c{3})
huda nawaf
2011년 11월 23일
Walter Roberson
2011년 11월 23일
How much RAM and swap space are you configured for now?
You are using the MATLAB Student Version, aren't you? Those are officially only the 32 bit versions, so if you cannot configure enough RAM and swap space in your existing system, then you will not be able to read larger files by getting more RAM.
Have you considered splitting your files in to even smaller pieces?
I have completely lost track of what you intend to do with the arrays once you have read them in?
Andrei Bobrov
2011년 11월 23일
a = accumarray([w,w1],w2,[],[],[],true)
Walter Roberson
2011년 11월 23일
Interesting, Andrei; I had quite forgotten that flag.
I am, however, not convinced at the moment that the array really is sparse; Huda earlier (in a different Question on this same topic) made reference to the array indices being sequential.
Fangjun Jiang
2011년 11월 22일
[I,J,V]=textread('test.txt','(%f,%f) %f');
A=zeros(2,3);
A(sub2ind(size(A),I,J))=V
Andrei Bobrov
2011년 11월 23일
[EDIT]
fid = fopen('nameyourfile.txt','r');
c = textscan(fid, '(%f,%f)%f','collectoutput',true);
fclose(fid)
a = accumarray(c{1}(:,1:2),c{1}(:,3),[],[],[],true)
[ADD] 22:32MSD
fid = fopen('nameyourfile.txt','r');
c1 = textscan(fid, '(%f,%f)%f');
fclose(fid);
a = sparse(c1{:});
카테고리
도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!