Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Changing empty array for peak width to zero

조회 수: 1 (최근 30일)
Binette Wadda
Binette Wadda 2020년 8월 17일
마감: MATLAB Answer Bot 2021년 8월 20일
So I have a matrix full of 25 iterations of a code (ends up as 75x25). For each iteration I wanted to calculate the width of the peak thats created, and I did this by using findpeaks. The problem is that my resulting width vector only includes 10 widths, and I'm assuming its because the other iterations do not have a peak, so the width is an empty array []. Is there a way I can insert zeros when they occur?
This is what I've tried
for i=1:25
[pks1(i,1), loc1(i,1), width1(i,1), prom1(i,1)]= findpeaks(XmRNA(:,i),t);
for i=1:length(width1)
if isempty(width1(i))
width1(i)= 0
end
end
end
I tried using is empty but my resulting width vector doesnt include the empty arrays ([]) so it doesnt work. (To clarify my width1 vector is 10 numbers, so there are no empty arrays to change to zero).
Any help is welcome!

답변 (1개)

Sindar
Sindar 2020년 8월 18일
편집: Sindar 2020년 8월 18일
% preallocate default values
pks1 = nan(25,1);
loc1 = nan(25,1);
width1 = zeros(25,1);
prom1 = nan(25,1);
for i=1:25
[tmp_pk, tmp_loc, tmp_width, tmp_prom]= findpeaks(XmRNA(:,i),t);
% if peak is found, update values with the *first* peak
if ~isempty(pks)
pks(i) = tmp_pk(1);
loc1(i) = tmp_loc(1);
width1(i) = tmp_width(1);
prom1(i) = tmp_prom(1);
end
end
you should think about whether you want the first peak or a different one (e.g., the most prominent peak)
Note: may be worth checking speed of parfor

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by