How to find out the index of the list for each number

1 回表示 (過去 30 日間)
tevzia
tevzia 2013 年 9 月 3 日
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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 3 日
編集済み: Azzi Abdelmalek 2013 年 9 月 3 日
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
  2 件のコメント
tevzia
tevzia 2013 年 9 月 3 日
Thank you alot
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 3 日
Look at edit

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 3 日
編集済み: Azzi Abdelmalek 2013 年 9 月 3 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 3 日
What is the relation between [1,0,0,1] and [1 4 3 1]
tevzia
tevzia 2013 年 9 月 3 日
i try to create list for number 1 and other numbers
[1,4,3,1]
for 1 [1,0,0,1] % shows 1 in this list and others 0
for 2 [0,0,0,0] % there is no 2 in the list
for 3 [0,0,1,0] there is number 3 which is third element of the list
for 4 [0,1,0,0} % number 4 is second element of the list.
I want to create new list for each number and show where is location with binary variables

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by