필터 지우기
필터 지우기

How to read files of different types?

조회 수: 3 (최근 30일)
AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 20일
편집: AbelM Kusemererwa 2015년 7월 24일
https://drive.google.com/file/d/0B4opCeiIoNAMTE9rTW9adVNNV0E/view?usp=sharing The link contains codes and 3 files(1 is a txt file and 2 & 3 are log files). I intend to input file name without without the file extension. File 1 is processed by button 1 whiles file 2 and 3 are processed by button 23. When button 23 is pressed it gives the opportunity for button 2 and 3 to be displaced for the respective files to be opened and read. However, I am having errors.
What I wanted to do was that for each case read the corresponding file and save them in columns (columns 1 to 15). Making sure that only rows with $GPGGA are read and saved in the case 1 and case 2. Whiles $GNGGA are read and saved in the case 3. Also in the codes, I used the for loop to select either $GNGGA or $GPGGA and also remove empty cells
Case 1 will be used to processes 1.txt file, case 2 for 2.log and case 3 for*3.log*.
These 3 files would be processed one at a time and I want it to be read so that all columns of the file being processed are saved.
  댓글 수: 7
Stephen23
Stephen23 2015년 7월 21일
Given that the "log" files are most likely text then you could have simply changed their file extension to .txt and uploaded them with the paperclip button.
AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 24일
I wanted to read the log file and work with it like the txt file

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 20일
fileID = fopen(filename,'r');
not
fileID = fopen('filename','r');
Your code also makes use of variables named things like col1 and col3, without having created those variables in any obvious way.
In your 1.txt file you have multiple different line formats, which makes it more difficult to process them automatically. Are there specific columns you need no matter what the string in the first field is?
  댓글 수: 3
Walter Roberson
Walter Roberson 2015년 7월 21일
datastring = fileread(textfile);
splitlines = regexp(regexp(datastring, '^\$GPGGA,.*$', 'match', 'lineanchors', 'dotexceptnewline').', ',', 'split');
GPGGA = vertcat(splitlines{:});
Now co11 = GPGGA(:,1); col2 = GPGGA(:,2); and so on, as cell array of strings. You can str2double(GPGGA(:,2)) to get the numeric values (without the leading 0's)
AbelM Kusemererwa
AbelM Kusemererwa 2015년 7월 24일
편집: AbelM Kusemererwa 2015년 7월 24일
It works for the files 1 and 2 but file 3 it doesn't. File 3 is GNGGA

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by