フィルターのクリア

How to add values into specific part of a zero vector

3 ビュー (過去 30 日間)
Frederik Bjerregaard
Frederik Bjerregaard 2022 年 2 月 25 日
コメント済み: Voss 2022 年 2 月 25 日
Hi
I want to create a vector that have the value of 1 in specific intervals and 0 everywhere else.
This is the code I have come up with but it doesn't work. flagstart indicates where the intervals with 1s should start and flagstop where they should stop so that there are 5 intervals (11600 to 22620 and so on)
res=zeros(151001,1);
flagstart = [11600 42410 72480 102100 132000];
flagend = [22620 52410 82550 112900 142200];
res(flagstart,flagend) = 1;

採用された回答

Voss
Voss 2022 年 2 月 25 日
res=zeros(151001,1);
flagstart = [11600 42410 72480 102100 132000];
flagend = [22620 52410 82550 112900 142200];
for ii = 1:numel(flagstart)
res(flagstart(ii):flagend(ii)) = 1;
end
  2 件のコメント
Frederik Bjerregaard
Frederik Bjerregaard 2022 年 2 月 25 日
Thank you!
Voss
Voss 2022 年 2 月 25 日
You're welcome! You almost had it!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by