How do I set variables for a code through txt file?

조회 수: 6 (최근 30일)
Konstantinos Angelos Maskalaris
Konstantinos Angelos Maskalaris 2021년 3월 31일
댓글: Sulaymon Eshkabilov 2021년 3월 31일
I have build my code but my professor wants me to be able to import the initial variables through a text file. For example variables x, y, z that are needed for the program to run. What exactly do I write in that text file? And do I simply call it through import data? Also he wants me to make the program create a text file with the results automatically.
  댓글 수: 2
Stephen23
Stephen23 2021년 3월 31일
Perhaps you could define them in a script (which is a text file).
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 3월 31일
If I understood your question ocrrectly, you'd need to write such a code that would import data from *.txt file for your variables x, y, z. And then after some calculations, it should export your data to another *.txt file. If this is the case, then you can write a code something similar to this one:
D0=load('IN.txt'); % Data Import from txt file called IN.txt
x=D0(1); % assign the imported data to x. Note there might be many values as well
y=D0(2); % assign the imported data to y.
z=D0(3); % assign the imported data to z.
F = ... % Do all necessary calculations
dlmwrite("OUT.txt", F) % Export the computed values to an external file called OUT.txt
Good luck

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

답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by