Find zeros in one variable and mark it in another one

2 ビュー (過去 30 日間)
Daria Ivanchenko
Daria Ivanchenko 2020 年 10 月 7 日
回答済み: Raunak Gupta 2020 年 10 月 9 日
Hi!
I have a code like this:
blinks = zeros(size(pupil_left));
% blinks(end+1,:) = zeros(size(pupil_left));
filter_pupil_left = find(pupil_left==0);
for k=1:length(filter_pupil_left)
blinks(filter_pupil_left(k)+(-70:70))=1;
end
I want to find all zeros in the variable "pupil_left" and mark them with ones in the variable "blinks", I also want to mark with ones 70 arrays before the first zero and 70 arrays after last zero. This code works but I would like to know how to do the same thing if I want to put ones not in the first row of the variable "blinks" but in the last one. I understand that I have to add some indexing to this line:
blinks(filter_pupil_left(k)+(-70:70))=1;
How can I do it? Should it be something like this?
blinks(filter_pupil_left(k)+(-70:70), [end+1,:])=1;
Thanks for your help!

採用された回答

Raunak Gupta
Raunak Gupta 2020 年 10 月 9 日
Hi,
Since blinks is a matrix, you need to give both indexes while accessing any row and column. Since that would be the correct syntax.
So if you want to update the first row, you can use below
blinks(1,filter_pupil_left(k)+(-70:70))=1;
Similarly for last row you can use
blinks(end,filter_pupil_left(k)+(-70:70))=1;
[end+1] will through an error because you are trying to access memory which is not allocated. end means last index in that dimension.

その他の回答 (0 件)

カテゴリ

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