Hi to all. Please help. I'm new in Matlab, so i don't really understnad why i get this error.
"Error using fscanf
Invalid file identifier. Use fopen to generate a valid file identifier. Error in gaspp (line 22)
num = fscanf(fid, '%d', [1,1]); % Number of nodes"
i found a code related to my project so i tried it and it was running. but when i finish input then it shows an error.
this is my code
disp('==============================');
disp('Masukkan Parameter Program');
disp('==============================');
f_input = input('>> Nama Input File : ','s'); % Contains network info
startNode = input('>> Node sumber : '); % Source node
endNode = input('>> Node tujuan : '); % Destination node
nind = input('>> Ukuran populasi : '); % Population size
Pc = input('>> Probabilitas crossover : '); % Crossover probability
Pm = input('>> Probabilitas mutasi : '); % Mutation probability
ngener = input('>> Batas generasi : '); % Generations limit
% -------------------------------------------------------------
% NETWORK BUILDING
% -------------------------------------------------------------
fid = fopen(f_input,'r');
*num = fscanf(fid, '%d', [1,1]);% Number of nodes*
edges = fscanf(fid, '%d', [1,1]);% Number of edges
source_node = zeros(1,edges);% Set of source nodes
dest_node = zeros(1,edges);% Set of end nodes
link_cost = zeros(1,edges);% Set of link cost
unlink_cost = 1000;% Set of unlink cost
thanks before

 채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 16일

0 개 추천

When you are prompted for Nama Input, you need to type in the name of an existing file.

댓글 수: 7

Khoirunnisya Zawawi
Khoirunnisya Zawawi 2016년 10월 17일
thank you for your answer, Walter. so i should make a new file for that? a blank file or what? cause when i get the code it's only contains some of .m file related to genetic algorithm (my project is about GA). thanks before
Walter Roberson
Walter Roberson 2016년 10월 17일
The file should contain two integers separated by whitespace (in text form). The first of them should be the number of nodes, and the second of them should be the number of edges.
Possibly code you did not show reads more information from the file.
Khoirunnisya Zawawi
Khoirunnisya Zawawi 2016년 10월 18일
like this 10 14; ? or [10 14];
Walter Roberson
Walter Roberson 2016년 10월 18일
Just numbers and spaces no brackets.
Khoirunnisya Zawawi
Khoirunnisya Zawawi 2016년 10월 19일
found it. thank you so much :)
Khoirunnisya Zawawi
Khoirunnisya Zawawi 2016년 10월 20일
편집: Walter Roberson 2016년 10월 21일
Hi Walter. i found another error in this code, its about horzcat. can you help me about it? this is my new question https://www.mathworks.com/matlabcentral/answers/308260-how-to-solve-this-error-error-using-horzcat-dimensions-of-matrices-being-concatenated-are-not-cons
i really appreciate it if you could help, thank you so much :)
Bagus Adhi
Bagus Adhi 2021년 6월 22일
I'm sorry maybe its to late for asking about this question now. I want to ask is "is there any code that should be changed to clear the error", cause i cannot find the answer by reading all the aswer between Ms. Khoirunnisya and Mr. Walter. I really need your help, this answer will help me for my Presentation. Thank You

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2016년 10월 16일

댓글:

2021년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by