how to make a looping function to delete all members in a phi set?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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].
Answers (1)
Rik
on 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 Comments
Muhammad Sam'an
on 2 Oct 2020
Rik
on 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
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!