how to make a looping function to delete all members in a phi set?
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
Let
let
phi= [ 1, 2 , 3, 4]
k=randi[(phi),1,1]
k=3
newphi(newphi==k)=[]
phi=[1,2,4]
I want to loop until phi = empty set .... I have used the for function but when it is executed it can't be because the number is randomized back to the initial phi or phi = [1,2,3,4].
Réponses (1)
Rik
le 2 Oct 2020
0 votes
You don't update the original variable, but you create a new one instead. You also have made a typo when writing the code here, because this isn't valid Matlab syntax.
2 commentaires
Muhammad Sam'an
le 2 Oct 2020
Rik
le 2 Oct 2020
phi=1:4;
while ~isempty(phi)
k=randi(max(phi));%not guaranteed to result in a match
phi(phi==k)=[];
%the code that actually does something with phi goes here
end
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!