Borrar filtros
Borrar filtros

Reshape won't work for my application. Why?

1 visualización (últimos 30 días)
Zach Dunagan
Zach Dunagan el 8 de Dic. de 2017
Comentada: Zach Dunagan el 8 de Dic. de 2017
Converting a line of Python code to matlab.
Here is the Python.
Fy_bern=np.sum(np.reshape(forceDist,(numPanels,1))*(np.sin(theta_t[t])*np.sin(theta)+np.cos(theta_t[t])*np.cos(theta)))
The matlab
Fy_bern = sum(reshape(forceDist, [numPanels, 1]) .* (sin(theta_t(t)) .* sin(theta) + cos(theta_t(t)) .* cos(theta)));
The error I get is Error using reshape To RESHAPE the number of elements must not change.
forceDist is a 32x30 from my understanding about reshape is it takes your array and puts it in a nxm matrix. I even abstracted reshape(forceDist, [numPanels, 1]) and ran it. Still gives me the same error.
reshape(forceDist, [numPanels, 1])
  2 comentarios
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan el 8 de Dic. de 2017
What is the value of numPanels? It should be 960.
Zach Dunagan
Zach Dunagan el 8 de Dic. de 2017
No, it's 32.

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 8 de Dic. de 2017
Reshape will NOT change the number of elements. Regardless of what something named reshape does in Python, MATLAB is not Python.
You need either to discard some of your elements or pad it sufficiently such that the number of elements is correct.
If this is behavior that you want to see, then nothing stops you from writing code that behaves as you wish. But reshape in MATLAB will not do what it is not programed to do.
  1 comentario
Zach Dunagan
Zach Dunagan el 8 de Dic. de 2017
I actually found a bug in the code which was preventing reshaping from working... Oops.

Iniciar sesión para comentar.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by