How to find out the index of the list for each number
    2 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hi, I try to make new index lists for numbers in my main list. Here is an example of the list
Schedule(1,4,3,1)
and i want a results like this
period1=(1,0,0,1) % first and second one is 1
period2=(0,0,0,0) %non of 2 in the list
period3=(0,0,1,0) 
period4=(0,1,0,0)
thank you
0 Commenti
Risposta accettata
  Azzi Abdelmalek
      
      
 il 3 Set 2013
        
      Modificato: Azzi Abdelmalek
      
      
 il 3 Set 2013
  
      EDIT
Schedule=[1,4,3,1];
m=numel(Schedule);
n=max(Schedule);
out1=zeros(n,m);
out1(sub2ind([n m],Schedule',(1:m)'))=1;
%Or
Schedule=[1,4,3,1];
m=numel(Schedule);
n=max(Schedule);
out=zeros(n,m);
for k=1:n
  idx=find(Schedule==k);
  out(k,idx)=1;
end
Più risposte (1)
  Azzi Abdelmalek
      
      
 il 3 Set 2013
        
      Modificato: Azzi Abdelmalek
      
      
 il 3 Set 2013
  
      period1=[1,0,0,1]
idx=find(period1==1)
%or
period1=[1,0,0,1;0,0,0,0;0,0,1,0;0,1,0,0]
out=cell2mat(arrayfun(@(x) find(period1(x,:)==1),1:size(period1,1),'un',0))
3 Commenti
Vedere anche
Categorie
				Scopri di più su Matrix Indexing in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!