how to make a looping function to delete all members in a phi set?
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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].
Risposte (1)
Rik
il 2 Ott 2020
0 voti
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 Commenti
Muhammad Sam'an
il 2 Ott 2020
Rik
il 2 Ott 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
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!