I keep getting this error "File identifier must be an integer-valued scalar of type double." when using fopen
31 views (last 30 days)
Show older comments
Adam Forman
on 19 Sep 2021
Answered: Sulaymon Eshkabilov
on 19 Sep 2021
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
Accepted Answer
Sulaymon Eshkabilov
on 19 Sep 2021
Err in the code:
filename = 'Example2.txt'; % Corrected ONE. No input() that creates the error
More Answers (1)
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!