フィルターのクリア

Reshape won't work for my application. Why?

1 回表示 (過去 30 日間)
Zach Dunagan
Zach Dunagan 2017 年 12 月 8 日
コメント済み: Zach Dunagan 2017 年 12 月 8 日
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 件のコメント
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017 年 12 月 8 日
What is the value of numPanels? It should be 960.
Zach Dunagan
Zach Dunagan 2017 年 12 月 8 日
No, it's 32.

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

回答 (1 件)

John D'Errico
John D'Errico 2017 年 12 月 8 日
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 件のコメント
Zach Dunagan
Zach Dunagan 2017 年 12 月 8 日
I actually found a bug in the code which was preventing reshaping from working... Oops.

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

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by