How can I make the index output of function into an array?

조회 수: 2 (최근 30일)
JJH
JJH 2018년 11월 16일
댓글: Adam Danz 2018년 11월 16일
I want to use the findpeaks function in matlab to find the maxima of my data set. I can get the location of each of these maxima by using locs and the width of each peak using w. The part of my function that does this is given by the code
function [pw, q, Wavelength, Intensity] = PeakFit(filename)
SpectrumData=csvread(filename)
Wavelength=SpectrumData(2:end-1,1);
Intensity=SpectrumData(2:end-1,2);
[pks locs w]=findpeaks(Intensity,'NPeaks',5,'SortStr','descend','MinPeakDistance',10,'MinPeakProminence',1*10^-6,'MinPeakWidth',2);
lambda = Wavelength(locs);
pw = (w*0.1);
end
However, I then want to be able to use lambda and pw as arrays, so that I can do the following commands:
q = lambda./(pw/2);
qvec = [q lambda];
qfac = sortrows(qvec,2);
i.e. I want to be able to extract particular elements of lambda and pw as if they were standard matrices. How can I achieve this?
  댓글 수: 1
Adam Danz
Adam Danz 2018년 11월 16일
Q1) what is the output of Wavelegth()? This is not a builtin matlab function. I'm assuming it's a vector whose size is equal to locs. If that assumption is correct, then lambda and pw are already arrays.
Q2) If the assumption above is correct, q should also be a vector the same saize as lambda; qvec should be a matrix with 2 columns, and qfac should be a columnar vector. Is that the case? If yes, what's the problem? If not, you'll need to give us more info about the Wavelength() output.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by