Make a vector of 1's and zeros

1 回表示 (過去 30 日間)
Bran
Bran 2014 年 8 月 21 日
コメント済み: Bran 2014 年 8 月 21 日
I could like to make a matrix consisting of 1's and zeros at certain points. I have a vector that is made up of two other vectors; C = [ A A1] and B = sort[C]
I wish to make a vector that is one at the points A and zero at A1. Because these are interspersed I am confused on how to do this. I tried using find but because A has a different length to C I cant use it for this purpose. Any ideas would be great :)

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 21 日
A=[1 2 3 4]
B=[2 6 1 5]
[C,idx]=sort([ A B])
C(idx<=numel(A))=1;
C(idx>numel(A))=0
  1 件のコメント
Bran
Bran 2014 年 8 月 21 日
Thank you very much for the help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConditional Mean Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by