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

1 次查看(过去 30 天)
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