필터 지우기
필터 지우기

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 CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by