Find function - scalar result?

Hello,
I'm trying to get the row number where my "goal" value (hier max time /10) is inside my tolerance of 0.001.
%Speed_profil.motorized.time -> Vector 100x1 from 0 to 4,5sec
Ramp=10;
goal = (Speed_profil.motorized.time(end,1)/Ramp);
idx_tol_mot = find(abs(Speed_profil.motorized.time-goal) < 0.001);
The fact to use the find funciton gives me a Vactor as a result.
I'm using this idx_tol_mot in an equation of the form y=ax+b to limit my Speed_profil.motorized.time vector (100x1 matrix).
Speed_profil.motorized.closing.values(1:idx_tol_mot,1) = (- a_mot * Speed_profil.motorized.time(1:idx_tol_mot,1));
Is there an alternative to the find function which can give a scalar variable? or can I convert the idx_tol_mot variable?
Thanks

Réponses (1)

Jan
Jan le 8 Avr 2021
Modifié(e) : Jan le 8 Avr 2021

0 votes

Maybe:
idx_tol_mot = find(abs(Speed_profil.motorized.time-goal) < 0.001, 1, 'first');
or
idx_tol_mot = find(abs(Speed_profil.motorized.time-goal) < 0.001, 1, 'last');
But this the output can be empty also, if no matching values are found.

3 commentaires

Cyril CRIER
Cyril CRIER le 8 Avr 2021
Modifié(e) : Cyril CRIER le 9 Avr 2021
Hello Jan, I'll try this.
EDIT: I've tried your solution, and it does not work unfortunately... I still get the error below, even though I see in my Base Workspace that idx_tol_mot is a 1x1 double matrix... (because I declare all my variables in a separate .m file)
For information, i'm using simulink with a Matlab function.
The error message is what appears when my pointer gets over the variable in the report.
EDIT: BTW. I've added the data idx_tol_mot as parameter in the matlab function
This is how the main error interface looks like:
Alexander Lachenmaier
Alexander Lachenmaier le 5 Mar 2022
Hi,
have you found a solution to this error? I am facing the exact same problem at the Moment.
Alex
Jan
Jan le 5 Mar 2022
@Alexander Lachenmaier: The original question wasn't clear. The OP showed a method, which replies a vector and asked, how to get a scalar. But when all we see is the code to produce a vector, it is impossible to guess, what it wanted instead.
Therefore I'm astonished, that you have "the same problem". Prefer to open a new thread and explain the details of your code.

Connectez-vous pour commenter.

Produits

Version

R2020a

Tags

Commenté :

Jan
le 5 Mar 2022

Community Treasure Hunt

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

Start Hunting!

Translated by