How to save output from the for loop in a matrixs?

조회 수: 3 (최근 30일)
Kabit Kishore
Kabit Kishore 2021년 3월 24일
댓글: Kabit Kishore 2021년 3월 25일
Hi i have a matrix with M x n dimension. I have performed the peak analysis for each column in the for loop. I want to save the output for the for loop as a matrix.
I have used the following for loop.
for i=x
[pks,locs]=findpeaks((i),'MinPeakHeight',Thresold)
end
I get output like this :
Thank you in advance
  댓글 수: 2
DGM
DGM 2021년 3월 24일
In this context, what is x in relation to your mxn matrix? What code precedes this?
Kabit Kishore
Kabit Kishore 2021년 3월 24일
X is the matrix of M x n

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 3월 24일
You can't pass (i) into findpeaks() - that's just a loop iterator, not a signal. You need to extract the column from your matrix. Then, since each column is not guaranteed to have the same number of peaks, you'll need a cell array to store the results.
[rows, columns] = size(data) % Size of your 2-D matrix of signals.
allPeakValues = cell(1, columns);
allPeakIndexes = cell(1, columns);
for col = 1 : columns
% Extract one column from the matrix.
thisColumn = data(:, col);
% Find the peaks in that column.
[thesePeakValues, theseIndexesOfPeaks] = findpeaks(thisColumn, 'MinPeakHeight', Threshold);
% Save the peaks for this particular column in our cell array that
% holds results for all the columns.
allPeakValues{col} = thesePeakValues;
allPeakIndexes{col} = theseIndexesOfPeaks;
end

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 3월 24일
Use Cell array to save the Matrices result
pks_data=cell(1,length(x));
locs_data=cell(1,length(x));
for i=1:x
[pks,locs]=findpeaks((i),'MinPeakHeight',Thresold);
pks_data{i}=pks;
locs_data{i}=locs;
end
  댓글 수: 1
Kabit Kishore
Kabit Kishore 2021년 3월 24일
편집: Kabit Kishore 2021년 3월 24일
Thank you, However it give error as shown below

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by