MATLAB Answers

Mingz Lee
0

Problems in opening/importing .asc files with headers.

Mingz Lee
さんによって質問されました 2019 年 6 月 17 日
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 6 月 17 日
Dear all,
Does anyone has the idea of opening such an .asc file? I am facing some problems of opening .asc files by codes. I tried the fopen function and the fread function, I cannot get rid of the headers and the matrix values become very ridiculars. And I also tried with the importdata function, I cannot get rid of the headers and all the data becomes one-column cell-type variables. My matlab version is R2017a. And I attached the data in the zip-file. Thanks in advance!
%% Test with the importdata
filepath = 'C:\Ming\Ming Research Labwork\Coding\20190617test\';
filename = strcat('irdata_001.asc');
fid = importdata([filepath filename], '\t');
%% Test with the fopen and fread.
filepath = 'C:\Ming\Ming Research Labwork\Coding\20190617test\';
filename = strcat('irdata_001.asc');
fid = fopen([filepath filename], 'r', 'n');
A = fread(fid,'double');

  1 件のコメント

Mingz Lee
2019 年 6 月 17 日
I just want to import the numbers and get rid of the headers from the data. And export them as a matrix and save them.

サインイン to comment.

1 件の回答

Star Strider
回答者: Star Strider
2019 年 6 月 17 日
 採用された回答

I was able to read it with this:
filename = 'rdata_001.asc';
fido = fopen(filename,'r');
D = textscan(fido, repmat('%s',1, 640), 'HeaderLines',9, 'CollectOutput',1, 'Delimiter','\t');
fclose(fido);
The result is a (512x640) cell array and looks like:
{'21327,00'} {'21328,00'} {'21327,00'} {'21323,00'} {'21325,00'} ...
{'21328,00'} {'21328,00'} {'21321,00'} {'21322,00'} {'21330,00'} ...
...
I will leave that to you to parse.
I have no idea what it is, although it says that it is an image of some sort, the header information (provided by Notepad) being:
[Settings]
Version=3
ImageWidth=640
ImageHeight=512
ShotRange=19605.86;20439.46
CalibRange=19412.02;27944.44
TempUnit=DV
[Data]
You can probably use str2double to extract the numbers. I left them as characters because I have no idea what that format means. If the (,) are decimal separators, it simply means all the data are integers, since everything after it are uniformly 0. You can then also use strrep to replace the (,) with (.) before using str2double.

  2 件のコメント

Mingz Lee
2019 年 6 月 17 日
Thanks to you! I managed to finish by your code. Yes, you are write it is a thermograph from IR camera. I should wirte my questions with more details. In the future, we are going to deal with hundreds of these kind of figures.
Star Strider
2019 年 6 月 17 日
As always, my pleasure!
Now that I know what it is, I am able to view it with:
Ds = strrep(D{:}, ',','.');
Dd = str2double(Ds);
figure
meshc(Dd)
view(0,90)

サインイン to comment.



Translated by