0

csvファイルのデータを読み書きしたいexifファイルがあります。

これは単なるサンプル ファイルです。実際のファイルは複雑で長すぎます。

---- 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
......
.......
.......

「召集.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ファイルへの書き込み

% 出力は次のようになります

% sample_out.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 に答える