The usage of [~,I]=min(abs(A+B)) on a specific example

4 vues (au cours des 30 derniers jours)
Rengin
Rengin le 4 Mai 2019
Commenté : Rengin le 4 Mai 2019
% Dear Users,
% I have a curve whose axes are defined as below:
u=[1.01 1.02 1.03 1.11 1.13 1.04 0.84 0.86 0.97 0.97]; % y-axis
t=[1 2 3 4 5 6 7 8 9 10]; %x-axis
uref=1;
umin=uref*0.90;
umax=uref*1.10;
% t= 1, 2, 3, 6, 9 and 10 --> for let's say 6 seconds, the u values are within the limit (0.90 (umin)<=u<=1.10(umax))
% t= 4, 5, 7 and 8 --> for 4 seconds, the u values are out of the limit
% Using the function of [~,I]=min(abs(A+B)) or [~,I]=min(abs(A-B)), how can I calculate t_total=4 seconds (out of limit time)?
% Thanks in advance!

Réponse acceptée

Stephen23
Stephen23 le 4 Mai 2019
Modifié(e) : Stephen23 le 4 Mai 2019
I don't really see how min can help you. Basic logical indexing would be simpler, e.g.:
>> nnz(u<umin | u>umax)
ans = 4
Note you can get both values using one logical index:
>> idx = u<umin | u>umax;
>> nnz(idx)
ans = 4
>> nnz(~idx)
ans = 6
  1 commentaire
Rengin
Rengin le 4 Mai 2019
Thanks it is very practical!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by