I am having a error using fprintf
Mostra commenti meno recenti
Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in main (line 159)
fprintf(f_id,'nx,ny, total: %6d %6d %12d \n', nx, ny,(2*nx+1)*(2*ny+1));
Here is the code chunck:
%---------- file output --------------------
dat_str = datestr(now,'yyyymmmdd@HH:MM');
eps_name = ['./results/inc',num2str(inc_disk*180/pi),'a',num2str(a),...
'_',dat_str,'.eps']; %output eps file name
txt_name = ['./results/BRT_',dat_str,'.txt'];
f_id = fopen(txt_name,'wt'); % export the data as ascii
%----- generate the output to a text file ----------
fprintf(f_id,'nx,ny, total: %6d %6d %12d \n', nx, ny,(2*nx+1)*(2*ny+1));
fprintf(f_id,'no. of rays hitting the disk, %10d \n', numb_disk);
fprintf(f_id,'no. of rays hitting black hole, %10d \n', numb_hole);
fprintf(f_id,'no. of rays from higher order images, %10d,\n', numb_high);
fprintf(f_id,'g_max = %12.4f, g_min = %12.4f \n', g_max, g_min);
fprintf(f_id,'mag_flux = %12.4f, mag_area = %12.4f \n',mu_flux, mu_area);
fprintf(f_id,'maximum error in Carter constant,%14.4E \n ', err_Q_max);
fprintf(f_id,'Degree of polarization: %f14.4 \n', del_total);
fprintf(f_id,'Angle of polarization chi (deg): %f14.4\n',chi_total*180/pi);
fprintf(f_id,'number of workers %8d \n',num_workers);
fprintf(f_id,'RT speed (rays per second) = %12.4f \n', rate_BRT);
fprintf(f_id,'Wall clock time (hours): %f14.4 \n', t_hour);
fclose(f_id);
Thank you
1 Commento
Bob Thompson
il 17 Gen 2019
What is the value of f_id?
My first guess from that error message is that f_id = -1, which means that it was unable to locate or create the file, and the error is not in fprintf at all.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Call C++ from MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!