Clear Filters
Clear Filters

using fscanf to open file

3 views (last 30 days)
Ronald Aono
Ronald Aono on 27 Oct 2019
Answered: Walter Roberson on 27 Oct 2019
clear all
TOL=[10^-3 10^-4 10^-5 10^-6 10^-7 10^-8 10^-9]
fileID = fopen('relp1.dat'); formatSpec = '%f';
A1= fscanf(fileID,formatSpec)
fileID = fopen('relp2.dat');
[A2]= fscanf(fileID,'%f')
fileID = fopen('relp3.dat');
[A3]= fscanf(fileID,'%f')
% sorting the data
A1INT=[A1(1,:) A1(3,:) A1(5,:) A1(7,:) A1(9,:) A1(11,:) A1(13,:)]
A1ND=[ A1(2,:) A1(4,:) A1(6,:) A1(8,:) A1(10,:) A1(12,:) A1(14,:)]
A2INT=[A2(1,:) A2(3,:) A2(5,:) A2(7,:) A2(9,:) A2(11,:) A2(13,:)]
A2ND=[ A2(2,:) A2(4,:) A2(6,:) A2(8,:) A2(10,:) A2(12,:) A2(14,:)]
A3INT=[A3(1,:) A3(3,:) A3(5,:) A3(7,:) A3(9,:) A3(11,:) A3(13,:)]
A3ND=[ A3(2,:) A3(4,:) A3(6,:) A3(8,:) A3(10,:) A3(12,:) A3(14,:)]
i keep runnnig into this error
Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in relp_dat (line 4)
A1= fscanf(fileID,formatSpec)

Answers (1)

Walter Roberson
Walter Roberson on 27 Oct 2019
filename = 'relp1.dat';
[fileID, msg] = fopen(filename);
if fileID < 0
error('could not open file "%s" because: "%s"', filename, msg);
I suspect that you will find that the filename is wrong with confusion between lower case L and digit 1, or else that the file is in a different directory.


Find more on Environment and Settings 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!