Accessing from parent folders!
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi, I am having troubles reading files from a parent folder. Basically I have set the DIR to the parent folder known as
DIR = 'C:\\BLah\\blah\\blah\\Information Retrieval\\CWKFOLDS';
I want to read the path but the textfile im reading from has it in this format ...
../fold2/d_affinia_1.oneline
how do i read from that using textread. I do not want to learn fopen as I have a deadline to meet and getting my head around that seems too complicated at this stage.
Kind Regards, Tanil
댓글 수: 0
답변 (2개)
Image Analyst
2012년 12월 13일
You will learn fopen() in about 20 seconds - quicker than it took you to write your question and you'll be done far far before your deadline. Then call fgets() or fgetl(). Then call fclose(). Exceedingly simple. Change your double backslashes to single backslashes or single forward slashes. Even Windows understands forward slashes believe it or not. You might use fileparts() and fullfile() to construct a filename.
댓글 수: 5
Walter Roberson
2012년 12월 13일
textdocument = '../fold2/d_affinia_1.oneline';
testTerms = regexp( fileread(textdocument), '[\r\n]', 'split');
testTerms will now be a cell array of strings, one entry per line.
Walter Roberson
2012년 12월 13일
olddir = cd(DIR);
TheData = textread('../fold2/d_affinia_1.oneline');
cd(olddir);
댓글 수: 2
Walter Roberson
2012년 12월 13일
I have no idea why theData.mat would get stored in that directory, unless you have a save() somewhere.
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!