I am designing a code to find the cheapest gear box pair that can meet a certain force requirement.
The requirement, for example in my code is WearPinionLD, is a 37x7 matrix, and Ft the force is 37x1 matrix. I intend to find the indices of the WearPinionLD of each row w.r.t the same row of Ft with for loop:
for i=1:37
index(i)=find(WearPinionLD(i,:)>=Ft(i));
end
but matlab said the LHS and RHS sized differently.

 채택된 답변

VBBV
VBBV 2022년 2월 27일
편집: VBBV 2022년 2월 27일

0 개 추천

WearPinionLD = rand(37,7);
Ft = rand(37,1);
for i=1:37
index{i} =find(WearPinionLD(i,:)>=Ft(i));
end
index.'
ans = 37×1 cell array
{[ 1 2 3 4 6 7]} {1×0 double } {[ 2 5 6 7]} {[ 6 7]} {[ 1 4 5 6 7]} {[1 2 3 4 5 6 7]} {1×0 double } {[ 2 3 4 6 7]} {[ 2 3 4 5 6 7]} {[ 2 3 4 7]} {[ 1 2 5 6 7]} {[ 1 4 6 7]} {[ 1 2 3 4 5 6]} {[ 3 4]} {[ 3 6]} {[ 1 3 4 5 6 7]}

댓글 수: 5

VBBV
VBBV 2022년 2월 27일
It finds indices for all columns.
Wayne Liu
Wayne Liu 2022년 2월 27일
it became 'Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-0.'...
VBBV
VBBV 2022년 2월 27일
Try it using cell array. See the edited code above.
VBBV
VBBV 2022년 2월 27일
As the indices array are irregularly sized based on find condition, use a cell array.
Wayne Liu
Wayne Liu 2022년 2월 27일
Probelm solved!!!! Thank you so much :))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 2월 27일

편집:

2022년 2월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by