Reading Text file from IMC company
6 views (last 30 days)
Show older comments
Dear All,
I am trying to read .raw files created by IMC measurement devices (basically it is a Text file). for that i am using the following code:
fid = fopen(FullRawData,'r');
Textall=fscanf(fid,'%c');
And in most cases it is working yet in some cases Matlab is not reading the correct text data. E.g.:
When showing the .raw file in WordPad:
|CF,2,1,1;|CK,1,3,1,1;|NO,1, 91,0,83,imc STUDIO 5.2 R13 (02.01.2020)@imc DEVICES 2.13R4 (2020-01-13)@imcDev__16200173@PC,0,;|NL,1, 8,1252,0x0;|CG,1, 5,1,1,1;|CD,2, 65, 2.000000000000000e-004,1,1,s,0,0,0, 0.000000000000000e+000,1;|NT,1, 14,1,1,1980,0,0,0;|CC,1, 3,1,1;|CP,1, 16,1,2,4,16,0,0,1,0;|CR,1, 59,1, -3.051944088384301e-001, 0.000000000000000e+000,1,1,A;|ND,1, 63, -1, -1, -1, 0.000000000000000e+000, 0.000000000000000e+000;|Np,1, 399,"imc1000" "Analog" 0 0,"imc1058" "200173" 0 0,"imc07" "0" 4 0,"ExpGuid" "d5c3232f-2ecd-4433-83eb-8688a4163b82" 0 0,"ORIGINALDATAPATH" "D:xxxxxxx\I3_Netz.raw " 0 0;|CN,1, 18,0,0,0,7,I3_Netz,0,;|Cb,1, 124, 1,0, 1, 1,0, 6000000, 0, 6000000,1, 2.216397344000004e+005, 1.296383160265600e+009,;|CS,1, 6000011, 1,æ
which is ok as i expected. Yet in matlab the Texall looks like this:
4 Comments
Rik
on 31 May 2021
It is not clear to me what kind of data you're expecting and how this is different from what you're getting. Are you sure the file was not changed by opening it with WordPad? Some rich text editors will attempt to repair a file when reading it. If the format doesn't actually match what the editor thinks, that may result in file damage. I would personally recommend Notepad++ if you want to explore plain text files.
You could also contact the author of that submission, either by posting a comment, or by sending an email.
Accepted Answer
Aubai
on 28 Jul 2021
2 Comments
Rik
on 28 Jul 2021
I doubt this works as intended with the file you shared, as the file isn't ASCII until the end.
You're also forgetting fclose.
fn=unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/637080/I3_Netz.zip');
FullRawData=fn{1};
fid1 = fopen(FullRawData,'r','a','US-ASCII');
tline = fgets(fid1),fclose(fid1);
Notice that from about halfway this array, the data isn't real ASCII anymore.
More Answers (1)
Jan
on 31 May 2021
Edited: Jan
on 28 Jul 2021
From a certain byte in the text the contents is not plain ASCII anymore. I guess boldly, that this was a problem during writing the data. If this is the case, there is no chance to repair the file afterwards.
2 Comments
Rik
on 31 May 2021
The function you linked to assumes everything in this file is plain ASCII. It is not. You can clearly see this if you open the file with Notepad++. You might be able to circumvent this by loading the file as uint8 and then casting to char. That will avoid Matlab from interpreting the file, which might be the part causing issues.
The main point is that the assumption is false: the file contains data that is not plain text. Any function based on that assumption is doomed to fail.
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!