input file - reading file

조회 수: 2 (최근 30일)
Eddy Ramirez
Eddy Ramirez 2020년 11월 5일
댓글: Mathieu NOE 2020년 11월 15일
Greetings,
I am working on an input file that should read my txt file (test.txt) and I was testing it to see if it reads it, but it does not read the .txt file. I am getting an error when I run it, I was wondering if you guys have an ideas as to why is giving me an error. Or do you guys have another approach that I could use instead of the txt file
any help would be greatly appreciated it
%%%DATA FOR MY INPUT FILE
10 10 1 %Sref bref cref
2 %patches
50 %nlattice for Patch 1
5 -5 0 1 -2 0 %x y z chord alphaol twist
0 0 0 1 -2 0 %x y z chord alphaol twist
50 %nlattice for Patch 1
0 0 0 1 -2 0 %x y z chord alphaol twist
0 0 0 1 -2 0 %x y z chord alphaol twist
0 1 10 %alpha_start alpha_step alpha_end

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 11월 5일
hello Eddy
a few minor buggs - corrected in you code
also no need to declare global variables - much more reliable to pass argument in functions
otherwise there was also a bug in your text file : the declared %Number of sections nlattice was not consistent with the actual number of lines below with data. There are only 2 lines of data while your declared 6 :
6 %Number of sections nlattice for Patch 1
5 -5 0 1 -2 0 % x y z chord alpha_0l twist %
0 0 0 1 -2 0
50 %lattice P2
6 %Number of sections nlattice for Patch 2
0 0 0 1 -2 0 % x y z chord alpha_0l twist %
5 5 0 1 -2 0
so changing the txt files + the minor bugs corrections = a solution that works !
hope it helped !
all the best , Mathieu
  댓글 수: 16
Eddy Ramirez
Eddy Ramirez 2020년 11월 14일
do you know what the reason could be as to why my DATA.s is throwing a negative number on the third row for x?
5.0000 -5.0000 0
3.3333 -3.3333 0
-1.6667 -1.6667 0
0 0 0
1.6667 1.6667 0
3.3333 3.3333 0
Mathieu NOE
Mathieu NOE 2020년 11월 15일
hello Eddy
there is (for me) an issue with the stop index of the first for loop and the start index of the second for loop
they are both equal to DATA.nlatall/2 ( = 3) (and this shouldn't be the case normally)
at the end of the first forr loop (when i = 3) : DATA.s(i,1) = 1.6667
but then you start the second for loop again at same index i = DATA.nlatall/2 ( = 3)
so you overwrite the previous values ,
and with the new equation for DATA.s(i,1) we get a negative value : DATA.s(i,1) = -1.6667
so for me there is a problem with the index when your first for loop must stop and when your second loop must start; the index should not be the same

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by