필터 지우기
필터 지우기

How to create an input file ?

조회 수: 30 (최근 30일)
omar ahmed
omar ahmed 2022년 8월 24일
답변: omar ahmed 2022년 10월 9일
Have certain inputs to my code. And I want to create an input file with this inputs and to be able to use this inputs in my code. And at the same time to be able to change them if I wanted.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2022년 8월 25일
@omar ahmed - what are the inputs? How many inputs are there? Please provide some details on the input file and the function (or script?) that reads the data.

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

채택된 답변

omar ahmed
omar ahmed 2022년 10월 9일
I found it. What I did to solve this problem is I wrote a matlab script that have all the variables in it (integer and string) and I run this script in the beginning of my code. I was able to use the variables
if true
Inputfile %matlab script name that have all var.
%code that uses this variables
end

추가 답변 (1개)

Pratik Pawar
Pratik Pawar 2022년 10월 7일
Please refer to the following code to read integer inputs from a file.
input_file = fopen('input_file_name', 'r'); % read the input file
if(input_file == -1)
error("File can't be read");
end
[number, count] = fscanf(input_file, "%d", 1);
while(count == 1)
fprintf("%d", number); % print the number
[number, count] = fscanf(input_file, "%d", 1); % read the next number
end
If the above information is not helpful, please feel free to add more details on the input file.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by