I keep getting this error "File identifier must be an integer-valued scalar of type double." when using fopen

32 visualizaciones (últimos 30 días)
I am trying to read in g-code text into matlabe using fopen and this error keeps appearing:
Could someone please help in deciphering this issue?
Here is my code:
clear
close all
clc
% Read in commands from text file
filename = input('Example2.txt');
fileID = fopen(filename,'r');
Dir = fscanf(fileID,'%f');
fclose(fileID);
% Store commands in "cmd" matrix
for i = 5:5:length(Dir)
for j = 1:1:5
cmd((i/5),j) = Dir(i+j-5,1);
end
end
cmd(:,3:4) = cmd(:,3:4) ./ 100;
Here is what the g-code file looks like:
1 1 0295 0000 000
2 1 0295 0000 365
1 4 0495 0000 000
2 4 0495 0000 365
1 4 0265 0000 000
2 4 0265 0000 365
1 4 0000 0000 000
2 4 0000 0000 185
1 3 0135 0000 000
2 3 0135 0000 365
  2 comentarios
Ive J
Ive J el 19 de Sept. de 2021
Editada: Ive J el 19 de Sept. de 2021
what's this line supposed to mean?!
filename = input('Example2.txt');
Why not just this:
fileID = fopen('Example2.txt', 'r');
Btw, readmatrix makes life a lot easier:
fileContent = readmatrix('Example2.txt');

Iniciar sesión para comentar.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Sept. de 2021
Err in the code:
filename = 'Example2.txt'; % Corrected ONE. No input() that creates the error

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 19 de Sept. de 2021
Most welcome!

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by