Reading unformatted text and converting to formatted
Show older comments
Hi,
I have some files that contain raw text that is unformatted. These files have lots of lines and all of these lines are along the lines of
RFCH[0][0]:1, RFCH[0][1]:2, RFCH[0][2]:3,
etc. What I need to do is assign the value to the right of the colon to a corresponding matrix location, so the first 1 would go to [0,0] ([1,1] since Matlab probably wouldn't recognize [0,0]).
I know I can open the file using
fid=fopen(projectdir, 'r')
T=textscan(fid, '%s')
fclose(fid)
I am not really sure how go about this. Any help would be great.
4 Comments
@Ibro Tutic: please do NOT remove your question like this. We are volunteers who give our time to help you and everyone else who might be reading this forum. When you delete your question you make our answers meaningless and pointless, and you make our information useless for everyone else as well. You are telling us that our volunteered time is worthless, that our efforts are not important, and that other people shall not learn from our efforts.
You have just made the answer below worthless, even though several people have spent their own time volunteering their time to help both you and other browsers of this forum.
Ibro Tutic
on 25 Nov 2015
Rena Berman
on 6 May 2021
(Answers Dev) Restored edit
Accepted Answer
More Answers (1)
dpb
on 24 Nov 2015
RFCH[0][0]:1, RFCH[0][1]:2, RFCH[0][2]:3,
fmt='RFCH[%d][%d]:%d';
fid=fopen('yorfile');
c=cell2mat(textscan(fid,fmt,'delimiter',',','collectoutput',1));
fid=fclose(fid);
X(c(:,1)+1,c(:,2)+1)=c(:,3);
1 Comment
Stephen23
on 24 Nov 2015
Subscripted assignment dimension mismatch.
Error in temp (line 5)
X(c(:,1)+1,c(:,2)+1) = c(:,3);
Categories
Find more on Text Data Preparation 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!