input file - reading file

1 次查看(过去 30 天)
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 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by