Stumped again... Converting Python to Matlab
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zach Dunagan
el 22 de Oct. de 2017
Comentada: Zach Dunagan
el 24 de Oct. de 2017
Here is the bit of Python code I am trying to convert to Matlab. code:
# thetas for each panel in global frame
theta=np.zeros((numPanels,1))
for i in range(numPanels):
theta[i]=np.arctan2(yp[i+1]-yp[i],xp[i+1]-xp[i])
output:
-2.63356
-2.92712
-2.98475
-3.01668
-3.03837
-3.05471
-3.06785
-3.07891
-3.08853
-3.09713
-3.10498
-3.11228
-3.11917
-3.12577
-3.13217
-3.13846
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.14159
3.13846
3.13217
3.12577
3.11917
3.11228
3.10498
3.09713
3.08853
3.07891
3.06785
3.05471
3.03837
3.01668
2.98475
2.92712
2.63356
0.508031
0.21447
0.156842
0.124909
0.103226
0.0868853
0.0737421
0.0626828
0.053059
0.0444609
0.0366123
0.0293165
0.0224263
0.0158261
0.00942088
0.00312805
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-0.00312805
-0.00942088
-0.0158261
-0.0224263
-0.0293165
-0.0366123
-0.0444609
-0.053059
-0.0626828
-0.0737421
-0.0868853
-0.103226
-0.124909
-0.156842
-0.21447
-0.508031
These are my Matlab arrays, where xpAdd = xp[i+1] and xp = xp[i]
xpAdd =
0.0600
0.0581
0.0562
0.0544
0.0525
0.0506
0.0488
0.0469
0.0450
0.0431
0.0412
0.0394
0.0375
0.0356
0.0319
0.0300
0.0281
0.0262
0.0244
0.0225
0.0206
0.0188
0.0169
0.0150
0.0131
0.0112
0.0094
0.0075
0.0056
0.0038
0.0019
0
-0.0019
-0.0038
-0.0056
-0.0075
-0.0094
-0.0112
-0.0131
-0.0150
-0.0169
-0.0188
-0.0206
-0.0225
-0.0244
-0.0262
-0.0281
-0.0300
-0.0319
-0.0338
-0.0356
-0.0375
-0.0394
-0.0412
-0.0431
-0.0450
-0.0469
-0.0488
-0.0506
-0.0525
-0.0544
-0.0562
-0.0581
-0.0600
-0.0600
-0.0581
-0.0562
-0.0544
-0.0525
-0.0506
-0.0488
-0.0469
-0.0450
-0.0431
-0.0412
-0.0394
-0.0375
-0.0356
-0.0319
-0.0300
-0.0281
-0.0262
-0.0244
-0.0225
-0.0206
-0.0188
-0.0169
-0.0150
-0.0131
-0.0112
-0.0094
-0.0075
-0.0056
-0.0038
-0.0019
0
0.0019
0.0038
0.0056
0.0075
0.0094
0.0112
0.0131
0.0150
0.0169
0.0188
0.0206
0.0225
0.0244
0.0262
0.0281
0.0300
0.0319
0.0338
0.0356
0.0375
0.0394
0.0412
0.0431
0.0450
0.0469
0.0488
0.0506
0.0525
0.0544
0.0562
0.0581
0.0600
xp' =
0.0600
0.0581
0.0562
0.0544
0.0525
0.0506
0.0488
0.0469
0.0450
0.0431
0.0412
0.0394
0.0375
0.0356
0.0319
0.0300
0.0281
0.0262
0.0244
0.0225
0.0206
0.0188
0.0169
0.0150
0.0131
0.0112
0.0094
0.0075
0.0056
0.0038
0.0019
0
-0.0019
-0.0038
-0.0056
-0.0075
-0.0094
-0.0112
-0.0131
-0.0150
-0.0169
-0.0188
-0.0206
-0.0225
-0.0244
-0.0262
-0.0281
-0.0300
-0.0319
-0.0338
-0.0356
-0.0375
-0.0394
-0.0412
-0.0431
-0.0450
-0.0469
-0.0488
-0.0506
-0.0525
-0.0544
-0.0562
-0.0581
-0.0600
Does anyone have an idea what this is doing theta[i]=np.arctan2(yp[i+1]-yp[i],xp[i+1]-xp[i]) ? I believe it's finding the angle and x1 and x2 points.
0 comentarios
Respuesta aceptada
Walter Roberson
el 22 de Oct. de 2017
It is finding the angle from (xp(i),yp(i)) to (xp(i+1),yp(i+1))
3 comentarios
Walter Roberson
el 22 de Oct. de 2017
Editada: Walter Roberson
el 22 de Oct. de 2017
Find the angles between what and each xp(i) and yp(i) ?
The code that is there now is answering the question: "if you are at (xp(i), yp(i)) and you want to go to (xp(i+1),yp(i+1)) then what angle do you need to travel?"
If that is not what you need to calculate, then please explain in words what you do need to calculate ?
If you are just looking for the MATLAB equivalent,
theta[i]=np.arctan2(yp[i+1]-yp[i],xp[i+1]-xp[i])
translates as
theta(i) = atan2(yp(i+1)-yp(i), xp(i+1)-xp(i));
and the code can be written without a loop as:
theta = atan2( diff(yp), diff(xp) );
When I glance at the python code I think it might possibly try to go past the end of the vector, but I am not certain as I do not use python.
Walter Roberson
el 22 de Oct. de 2017
Editada: Walter Roberson
el 24 de Oct. de 2017
The MATLAB equivalent code is:
% thetas for each panel in global frame
theta = zeros(numPanels, 1);
for i = 1 : numPanels
theta(i) = atan2( yp(i+1)-yp(i), xp(i+1)-xp(i) );
end
If numPanels is not at least one less than length(xp) then this code will crash trying to go past the end of xp or yp. (You said you wanted the equivalent MATLAB code, not that you wanted correct code.)
Más respuestas (1)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!