# Vector loading with constraint and saving in vector

1 view (last 30 days)
Daeyeon Koh on 31 Aug 2021
Commented: Daeyeon Koh on 31 Aug 2021
Hi.
I found, and saved peaks information in vector in the cell 'A' with 'findpeaks' function.
And I could see the saved vector array.
I'd like to collect the peak vectors in the range (1<loc<10).
But with this script, I can only get peak values(pks) in the 'B' cell, not vector([pks, locs]).
How can I save disirable vectors in the cell 'B'?
clc;
clear all;
[numbers,strings,raw]=xlsread('C:\Users\marett\Desktop\0310 FFT');
[row, col]=size(numbers);
numArrays = row-2;
A=cell(numArrays,2);
B=cell(numArrays,2);
x=numbers(:,2);
for n=1:col
y=numbers(:,n+2);
ys=smooth(y,50,'sgolay',5);
[pks,locs] = findpeaks(ys,x,'MinPeakDistance',0.5);
A{n}=[pks,locs];
B{n}=A{n}(locs>1&locs<10);
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Chunru on 31 Aug 2021
clc;
clear all;
[numbers,strings,raw]=xlsread('C:\Users\marett\Desktop\0310 FFT');
[row, col]=size(numbers);
numArrays = row-2;
A=cell(numArrays,2);
B=cell(numArrays,2);
x=numbers(:,2);
for n=1:col
y=numbers(:,n+2);
ys=smooth(y,50,'sgolay',5);
[pks,locs] = findpeaks(ys,x,'MinPeakDistance',0.5);
A{n}=[pks,locs];
B{n}=A{n}(locs>1&locs<10, :); % Add ", :" here
end
##### 1 CommentShowHide None
Daeyeon Koh on 31 Aug 2021
Thank you for your clear answer!

Sign in to comment.

R2019b

### Community Treasure Hunt

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

Start Hunting!