Find indices with for loop

1 visualización (últimos 30 días)
Wayne Liu
Wayne Liu el 27 de Feb. de 2022
Editada: VBBV el 27 de Feb. de 2022
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.

Respuesta aceptada

VBBV
VBBV el 27 de Feb. de 2022
Editada: VBBV el 27 de Feb. de 2022
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 comentarios
VBBV
VBBV el 27 de Feb. de 2022
As the indices array are irregularly sized based on find condition, use a cell array.
Wayne Liu
Wayne Liu el 27 de Feb. de 2022
Probelm solved!!!! Thank you so much :))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by