Decide values of row in matrix for certain row intervals

2 ビュー (過去 30 日間)
Frederik Bjerregaard
Frederik Bjerregaard 2022 年 3 月 5 日
回答済み: AndresVar 2022 年 3 月 5 日
Hi
I need to create a matrix where each row has the values of [1,0,0,0] over certain intervals as given below
rows=150001;window=500;
res=zeros(rows-window,4);
flagstart = [11600 42410 72480 102100 132000];
flagend = [22620 52410 82550 112900 142200];
for ii = 1:numel(flagstart)
res(flagstart(ii):flagend(ii),:) = [1,0,0,0];
end
This is the code i have got so far, but it is not working when i run it.

採用された回答

Scott MacKenzie
Scott MacKenzie 2022 年 3 月 5 日
rows=150001;window=500;
res=zeros(rows-window,4);
flagstart = [11600 42410 72480 102100 132000];
flagend = [22620 52410 82550 112900 142200];
for ii = 1:numel(flagstart)
n = flagend(ii) - flagstart(ii)+1;
res(flagstart(ii):flagend(ii),:) = repmat([1,0,0,0],n,1);
end

その他の回答 (1 件)

AndresVar
AndresVar 2022 年 3 月 5 日
since you are just changing the first number, use res(a:b,1)=1

カテゴリ

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