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

29 Ansichten (letzte 30 Tage)
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 Kommentare
Ive J
Ive J am 19 Sep. 2021
Bearbeitet: Ive J am 19 Sep. 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');

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 19 Sep. 2021
Most welcome!

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by