Filter löschen
Filter löschen

Reshape won't work for my application. Why?

1 Ansicht (letzte 30 Tage)
Zach Dunagan
Zach Dunagan am 8 Dez. 2017
Kommentiert: Zach Dunagan am 8 Dez. 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 Kommentare
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 8 Dez. 2017
What is the value of numPanels? It should be 960.
Zach Dunagan
Zach Dunagan am 8 Dez. 2017
No, it's 32.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 8 Dez. 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 Kommentar
Zach Dunagan
Zach Dunagan am 8 Dez. 2017
I actually found a bug in the code which was preventing reshaping from working... Oops.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by