How to update global logical array from local logical array.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Windel Hotdog
le 23 Août 2022
Réponse apportée : Kartikay Sapra
le 26 Août 2022
Hi, dear Community,
I want to create something like this:
i have global logical_array = [1,1,1,1,1,1,1,1]
I want to change the logical array to zero based on the sequence (the smallest value first)
from A: 1 (index 3) to be remove as first, then 2(index 5) as second, then 3(index 4) as third, then 4(index 1) as forth and 4 (index 5) as fifth,
from log_array = [1,1,0,1,1,1,1,1,], then [1,1,0,1,0,1,1,1], then [1,1,0,0,0,1,1,1], then [0,1,0,0,0,1,1,1], then [0,0,0,0,0,1,1,1],
At the same time i want to write the logical array into Zero, when that global position has been removed.
The end answer of logical array should be [0 0 0 0 0 1 1 1].
The loop should run until no values is < f_min.
How can i do this step by step?
Thanks a lot.
log_array = [true, true, true, true, true, true, true, true];
A = [4 4 1 3 2 7 8 9]';
DoF = 4;
f_min = 5;
r = length(A)-DoF;
while r ~= 0
if any (A< f_min)
[A_diff, f_id] = min(A-f_min);
log_array (f_id) = 0 %%Problem here
A (f_id) = []
r = length(A)-DoF; %r will be reduced by one in every loop
end
end
0 commentaires
Réponse acceptée
Kartikay Sapra
le 26 Août 2022
The issue with this approach is, whenever the size of the array is reduced, the indexing resets. Moreover, the global logical array does not change in size so it follows the initial indexing.
You may use the following logic:
log_array = [true, true, true, true, true, true, true, true];
A = [4 4 1 3 2 7 8 9]';
DoF = 4;
f_min = 5;
r = length(A)-DoF;
while r >= 0
if any (A< f_min)
[A_diff, f_id] = min(A-f_min);
log_array (f_id) = 0 %%Problem here
A (f_id) = intmax;
r = r-1; %r will be reduced by one in every loop
end
end
A = A(log_array)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays 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!