My error is the ever popular ::::Error using fprintf Invalid file identifier. Use fopen to generate a valid file identifier. Error in pro1 (line 7) fprintf(fileID,'edges\t initial_nodes\t nodes_after_reduction\t difference \n')
조회 수: 2 (최근 30일)
이전 댓글 표시
prompt="enter g value";
g=input(prompt);%To choose the type of graph
if g == 1
fileID = fopen('output2\cycle_graph_output.txt','w')%Creates a output text file
fprintf(fileID,'edges\t initial_nodes\t nodes_after_reduction\t difference \n')
myfolderinfo = dir('cycle_graph') ; %lists folder contents
N = length(myfolderinfo) ; % number of files in the folder
else if g == 2
fileID = fopen('output2\wheel_graph_output.txt','w')
fprintf(fileID,'edges\t initial_nodes\t nodes_after_reduction\t difference \n')
myfolderinfo = dir('wheel_graph') ;
N = length(myfolderinfo) ;
else if g == 3
fileID = fopen('output2\windmill_graph_output.txt','w')
fprintf(fileID,'edges\t initial_nodes\t nodes_after_reduction\t difference \n')
myfolderinfo = dir('windmill_graph') ;
N = length(myfolderinfo) ;
end
end
end
for i = 3:N %To iterate through every file in the respective directory
thisfile = myfolderinfo(i).name
A=readmatrix([myfolderinfo(i).folder '\' myfolderinfo(i).name],'Whitespace',' []');%Reads data as matrix from all the files in the respective directory
[n,k] = size(A);
///this code works fine in the Matlab in my local system.But the errors arise when i try to run it on Matlab online.What changes can i make to it to work on Matlab online?
답변 (1개)
Steven Lord
2020년 3월 17일
You never check that fopen was able to successfully open the file for writing before you try writing to it. Call fopen with two output arguments. If the first output argument is -1, check the second output argument for more information about why fopen was unable to open the file.
댓글 수: 0
커뮤니티
더 많은 답변 보기: 원격 교육 커뮤니티
참고 항목
카테고리
Help Center 및 File Exchange에서 Platform and License에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!