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

31 views (last 30 days)
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 Comments
Ive J
Ive J on 19 Sep 2021
Edited: Ive J on 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');

Sign in to comment.

Accepted Answer

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

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Sep 2021
Most welcome!

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!