0

我有一个 exif 文件,我想在 csv 文件中读取和写入数据。

这只是一个示例文件,真实的文件太复杂太长。

---- File ----
File Name                       : IMG_5547.JPG
Directory                       : .
File Size                       : 3.1 MB
File Modification Date/Time     : 2013:05:27 18:10:31+02:00
File Access Date/Time           : 2013:06:19 13:53:37+02:00
File Creation Date/Time         : 2013:06:19 13:53:37+02:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 4000
Image Height                    : 3000
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:2 (2 1
......
.......
.......

'muster.txt'

File Name                       : IMG_5547.JPG
GPS Time Stamp                  : 08:52:21
GPS Latitude                    : 52.419358°
GPS Longitude                   : 9.652666°
GPS Altitude                    : 140.1 m

% 读取文件

fid = fopen('muster.txt','r');

filename_ = fgetl(fid);
Skip2_ = fgetl(fid);   // **HOW CAN I SKIP MORE THAN ONE LINE ?????**
GPS_Latitude =fgetl(fid);
GPS_Longitude =fgetl(fid);
GPS_Altitude =fgetl(fid);
fclose(fid);

% 写入 csv 文件

% 输出应该是这样的

% 样本输出.csv

IMG_5547  52.419358  9.652666  140.1

我想知道如何从 ('filename_,'GPS Latitude','GPS_Longitude','GPS_Altitude') 获取所需的值并写入 csv 文件

4

1 回答 1

1

以下是我将如何解决这个问题:

% read in the file and convert to array of characters
fid = fopen('muster.txt');
A = char(fread(fid))';
fclose(A);
% create a cell array of strings for each line in the file
fileLines = regexp(A,'\n','split');
% use the ' : ' as a kind of delimiter between the field name
% and the data
toks = regexp(fileLines,'\s+:\s+','split');
% create a structure to hold the data, and fill it
data = struct();
for ii=1:length(toks)
  currTok = toks{ii};
  data.(char(regexprep(currTok{1},'\s+',''))) = char(regexprep(currTok{2},'\s+',''));
end
% write the csv file
fid = fopen('sample_out.csv','w');
fprintf(fid,'%s %s %s %s %s\n,...data.FileName, ...
                                 data.GPSTimeStamp, ...
                                 data.GPSLatitude, ...
                                 data.GPSLongitude,data.GPSAltitude);
fclose(fid);

当然,还有更有效的方法,但鉴于问题陈述,我将从这里开始。

于 2013-06-20T15:03:16.850 回答