error in using fscanf

1 次查看(过去 30 天)
Skydriver
Skydriver 2019-4-21
I have a script like this:
%Inputing POE
file_01='POE_0.01.txt';
fid=fopen(file_01, 'r');
FileName_01=fscanf(fid,'%g %g %g', [3,Inf])';
Mag_01=FileName_01(:,1); % moment magnitude
Dist_01=FileName_01(:,2); % distance
POE_01=FileName_01(:,3); % probability of exceedance
I = (mod(1:length(Mag_01),30)==1);
Mag = Mag_01(I);
Dist = Dist_01(1:30);
POE_01 = reshape(POE_01,30,15);
marginal(1:15,1) = sum(POE_01);
file_POE = ['POE_0.5.txt','POE_0.2.txt','POE_0.1.txt','POE_0.05.txt', ...
'POE_0.02.txt','POE_0.01.txt','POE_0.005.txt'];
for i = 1:7
file_temp=file_POE(i);
fid=fopen(file_temp, 'r');
FileName_temp=fscanf(fid,'%2.2f %g %g', [3,Inf])';
POE=FileName_temp(:,3); % probability of exceedance
marginal(1:15,i)=sum(reshape(POE,30,15));
temp=sum(marginal);
hold on
plot(Mag,marginal(1:15,i)/temp(i),'DisplayName',file_POE(i))
xlabel('Magnitude (Mw)');
ylabel('Contribution to the Hazard');
end
xlim([4.5 8.8])
legend
I got a massage about :
Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in inputing_data (line 73)
FileName_temp=fscanf(fid,'%g %g %g', [3,Inf
Is there any one can help?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by