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!