fread() help. "Error using fread: Invalid file identifier..."
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jose Godinez
el 27 de Jun. de 2019
Comentada: Jose Godinez
el 1 de Jul. de 2019
Hello everyone,
I am currently working in analyzing a set of data in the PTU format using a script called "Read_PTU_V1.m". However, I had an issue while running it. After the program opened a dialog box to select a file from my PC, I ran into the following error.
Error using fread
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Read_PTU_V1 (line 57)
Magic = fread(fid, 8, '*char');
I have attached the section that I believe will present a good idea on what is the problem I have. It starts in line 53 and goes down to line 60.
% start Main program
[filename, pathname]=uigetfile('*.ptu', 'T-Mode data:'); %Opens dialog box to manually select the file using file explorer
fid=fopen(filepath);
Magic = fread(fid, 8, '*char');
if not(strcmp(Magic(Magic~=0)','PQTTTR'))
error('Magic invalid, this is not an PTU file.');
end;
I didn't write this script and honestly have no idea how to make it work. Please help a poor man with no matlab experience. I have attached the file as an extra resource.
0 comentarios
Respuesta aceptada
dpb
el 28 de Jun. de 2019
[filename, pathname]=uigetfile('*.ptu', 'T-Mode data:'); %Opens dialog box to manually select the file using file explorer
fid=fopen(filepath);
Well, no, this could never have worked as written...the script returns the file and path in variables filename and pathname but then uses something entirely different to try open a file. That makes no sense whatsoever.
You'll have much better chance with something like
[filename, pathname]=uigetfile('*.ptu', 'T-Mode data:'); %Opens dialog box to manually select the file using file explorer
fid=fopen(fullfile(pathname,filename),'r');
You should then by all rights check for fid<0 and show any error messages if so...there's examples in the doc for fopen for such.
Doesn't engender much confidence in the rest of the script with such a horrible problem right off the bat...presuming it's as was distributed and not somehow butchered by other than the author.
Más respuestas (0)
Ver también
Categorías
Más información sobre String Parsing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!