For loop assistance- incorrect data

4 ビュー (過去 30 日間)
Eddy Ramirez
Eddy Ramirez 2020 年 11 月 14 日
コメント済み: Are Mjaavatten 2020 年 11 月 16 日
Greetings,
I am running the attached files, but I am running into an issue with DATA.s. I would like to get the following data
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
But instead, my coding is providing the following
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
I cant figure it out as to why I am getting a negative (-1.6667) on the first columnt/third row
any feedback would be greatly appreciated it
  2 件のコメント
John D'Errico
John D'Errico 2020 年 11 月 14 日
Learn to use the debugger! You will have your answer in far less time than it takes to wait for someone to download your code, figure out how to use it, and then run it, all the while, using the debugger themselves.
Eddy Ramirez
Eddy Ramirez 2020 年 11 月 14 日
I am using the debugger and that is how I was able to find the mistake ... thank you for your feedback

サインインしてコメントする。

回答 (1 件)

Are Mjaavatten
Are Mjaavatten 2020 年 11 月 15 日
You give DATA.s(3,1) the desired value in line 8 of exec2w. Then you overwrite it with the wrong value in line 22.
I found debugging your code confusing at first. This was caused by your declaration of DATA as global. The use of global variables is generally discouraged in Matlab, as they tend to lead to confusing effects. In this case the confusion stemmed from the fact that global variables survive the 'clear' command, so I struggled a bit with finding which function actually set the values. ('clear all' does the trick, it turns out.)
Your code runs exactly the same if you delete all 'global DATA' commands, as DATA is transferred in the function calls.
  2 件のコメント
Eddy Ramirez
Eddy Ramirez 2020 年 11 月 15 日
so add the "clear all"? if so, where should I add it?
Are Mjaavatten
Are Mjaavatten 2020 年 11 月 16 日
Type "clear all" in the command window before calling exex2w.
If you avoid the unnecessary global declarations you will not need the "clear all" any more. At least not in this context.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by