How can i have the posterior minimum and position of that?

7 visualizaciones (últimos 30 días)
Xiomara Escobar
Xiomara Escobar el 7 de Nov. de 2020
Respondida: Darshak el 16 de Abr. de 2025
Hello, I have a problem, I have the maximum of a vector, and I have to obtain posterior minimum and the position of that, i have this code, and it's ok but in the cell number 41 the maximum is the last number of the matrix, so Seg_leng-posi_max is 0, and matlab say me that: Second argument must be a positive scalar integer.
I don't know what to do for that case.
for l=1:length(Rd)
for k=1:1:num_Seg
[maxim(l,k),posi_max(l,k)]=max(x{l,k});
[posi_min{l,k},column{l,k},cero{l,k}]=find(x{l,k}<0,Seg_leng-posi_max(l,k),'last');
end
end
Seg_leng is the length of mi cell, 200, posi_max, is the position where is my maximum.
i

Respuestas (1)

Darshak
Darshak el 16 de Abr. de 2025
I see what you're dealing with. The code runs into a problem when the maximum value is at the last index because there's nothing to its right. This results in the code trying to pass zero to the “find” function instead of the intended segment of the vector. To tackle this, we need to handle it as a special case. Here's a tweak we can use:
for l = 1:length(Rd)
for k = 1:num_Seg
[maxim(l,k), posi_max(l,k)] = max(x{l,k});
% Check if the maximum is at the last position
if posi_max(l,k) < Seg_leng
[posi_min{l,k}, column{l,k}, cero{l,k}] = find(x{l,k} < 0, Seg_leng - posi_max(l,k), 'last');
else
% Handle the case where the maximum is at the last position
posi_min{l,k} = [];
column{l,k} = [];
cero{l,k} = [];
end
end
end
Hope this helps!

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by