how to find the first element that satisfy a condition in a matrix?
9 次查看(过去 30 天)
显示 更早的评论
Hallo,
I have a matrix describes the difference between secuencial elements Dwf (127*2398).
now I want to find out the first element (column-wise) that satisfy the condition < 0.01 then starting from this element I want to find the first element that is < 0 and make a new matrix limited with the elements bewteen this two conditions as in the following : ( first_element : last_element +1)
I have tried some coding but it didn't work out so far, I am still a beginner with MATLAB.
hope someone could help and thatnks in advance
for i=6:127 % the rows, I must start from the 6th row
for j = 1:2700 % the columns
first_element(:,j) = find(Dwf(:,j)> 0.01,1,'first');
last_element(:,j) = find(Dwf(:,j) < 0 & j > first_element,1,'first') ;
end
end
4 个评论
采纳的回答
Bruno Luong
2018-11-13
Try this
for j = 1:ny
idx_start(:,j) = find(Dwf(:,j)> 0.01,1,'first') ;
idx_end(:,j) = find (Dwf(:,j) < 0 & (1:nx)' > idx_start(:,j) , 1, 'first');
end
更多回答(1 个)
KSSV
2018-11-13
编辑:KSSV
2018-11-13
YOu may follow something like below:
load('dwf.mat')
[nx,ny] = size(Dwf) ;
iwant = NaN(size(Dwf)) ;
for i = 1:ny
idx1 = find(Dwf(:,i)<0.01) ; idx1 = idx1(1) ;
idx2 = find(Dwf(:,i)<0.) ; idx2 = idx2(1) ;
iwant(idx1:idx2,i) = Dwf(idx1:idx2,i) ;
end
pcolor(iwant) ;
shading interp ;
colorbar
YOu have to check the conditions properly.
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!