Problems in opening/importing .asc files with headers.

5 views (last 30 days)
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 Comment
Mingz Lee
Mingz Lee on 17 Jun 2019
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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 17 Jun 2019
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 Comments
Mingz Lee
Mingz Lee on 17 Jun 2019
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
Star Strider on 17 Jun 2019
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)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!