how to make a looping function to delete all members in a phi set?

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)

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

so, please give me the solution of mathlab code?
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.

Tags

Asked:

on 2 Oct 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!