Help finding error in Matlab code

4 次查看(过去 30 天)
Zach Dunagan
Zach Dunagan 2017-11-11
编辑: Zach Dunagan 2017-11-20
I have two sets of code, one in Python and the other in Matlab. I am converting Python to Matlab, but ran into a error that I am having a difficult time trouble shooting. There erros is...
Index exceeds matrix dimensions.
Error in unSteadyTEvortexShedding (line 167)
[xVV(i, j), yVV(i, j)] = VortexPointOnPt(xVorPos(i),
yVorPos(i), xVorPos(j), yVorPos(j), 0);
I have attached the VortexPointOnPt function file as well. The indexing is occurring at the while loop with k or the for loops?
  4 个评论
Zach Dunagan
Zach Dunagan 2017-11-14
编辑:Zach Dunagan 2017-11-14
Both of you make some great points. Jan, what is the Matlab equivalent to that of Python?
Donald, I got the code to run. Thank you for your suggestions. I was just not thinking clearly.
Jan
Jan 2017-11-14
编辑:Jan 2017-11-14
@Zach: The equivalent of what in Python? All I see is a meaningless Matlab command:
filepath = savepath('C:/FramesMatlab')
But I cannot know, which Python command you want to replace. Perhaps:
pathName='C://Users//Zach Dunagan//Desktop//frames//'
Then:
filepath = 'C:/FramesMatlab';

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2017-11-14
编辑:Jan 2017-11-14
You define xVorPos and yVorPos:
xVorPos = zeros(numFrames, 1);
yVorPos = zeros(numFrames, 1);
Then you run a loop:
for t = 1:numFrames % for each time frame
Inside this loop you check
if t > 0
repeatedly, but this is impossible, when the loop runs from 1:numFrames. Omit this tests to reduce clutter. You access:
for j =1:t
... xVorPos(j), yVorPos(j)
before the failing line successfully. Therefor I cannot imagine, why
for i = 1:t
for j = 1:t
if i == j
xVV(i, j) = yVV(i,j) == 0;
else
[xVV(i, j), yVV(i, j)] = VortexPointOnPt(xVorPos(i), yVorPos(i), ...
xVorPos(j), yVorPos(j), 0);
fails some lines later.
What is the purpose of:
xVV(i, j) = yVV(i,j) == 0;
This sets xVV(i,j) to 1, if yVV(i,j) is 0, and to 1 otherwise. Is this wanted? If so, it is strange, because you have defined
xVV = zeros(t, t);
yVV = zeros(t, t);
explicitly. Or do you want to set xVV(i,j) and yVV(i,j) both to zeros? If so, omit this, because the zeros set this value already.
There are so many strange and confusing commands in your code, that I think the most efficient way to debug it is to delete it and rewrite in in Matlab from scratch. Digging in the mud does not produce reliable and clean code. You cannot write an English article by typing it in German, use Google's auto-translator and fix the errors afterwards.
  1 个评论
Zach Dunagan
Zach Dunagan 2017-11-14
编辑:Zach Dunagan 2017-11-14
I told Donald I found the bug in the previous comment.
The code I am referring to is... pathName='C://Users//Zach Dunagan//Desktop//frames//'
You said perhaps it would be... filepath = 'C:/FramesMatlab'
Thank you.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2017-11-14
As I described in a previous question, in Python, setting pathName is just setting a variable, with no side effects and no special meaning. It is just another variable name. It is also unused in the code you posted, so you can simply delete the line.
  7 个评论
Zach Dunagan
Zach Dunagan 2017-11-15
编辑:Zach Dunagan 2017-11-15
I manage to figure it out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by