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].

Risposte (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 Commenti

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

Questa domanda è chiusa.

Tag

Richiesto:

il 2 Ott 2020

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by