Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

[Help] syms and file *.txt

조회 수: 3 (최근 30일)
trung trinh
trung trinh 2011년 11월 28일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a file *.txt with its content
q1 q2 q3 q4 q5 q6 q7 q8 q9 q10
Normally, in [command window] i must type
syms q1 q2 q3 q4 q5 q6 q7 q8 q9 q10
to declatation.
But Now i want to use [command window] to read file *.txt and declaration automatically. I only change file *.txt

답변 (2개)

Walter Roberson
Walter Roberson 2011년 11월 28일
You could try
vars = regexp( fileread('YourFile.txt'), ' ', 'split');
syms(vars{:});
However, I do not promise that it will work (I cannot test it this evening.) If it does not work, then you will require at least one run-time command evaluation, which is not a good idea.
Have you considered renaming your .txt file as a .m file, adding "syms" to the beginning of the line, and using run() to execute the file as a script?

trung trinh
trung trinh 2011년 11월 28일
Error: Not a valid variable name. :(
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 11월 28일
Does your text file contain other things as well? If so then the fileread() would have to be replaced with code that read just the first line of the file.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by