필터 지우기
필터 지우기

using fscanf to open file

조회 수: 1 (최근 30일)
Ronald Aono
Ronald Aono 2019년 10월 27일
답변: Walter Roberson 2019년 10월 27일
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)
fclose(fileID);
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)

답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 27일
filename = 'relp1.dat';
[fileID, msg] = fopen(filename);
if fileID < 0
error('could not open file "%s" because: "%s"', filename, msg);
end
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by