Output a plot and a matrix from a function

6 ビュー (過去 30 日間)
Miranda Gabriel
Miranda Gabriel 2022 年 4 月 21 日
回答済み: Sam Chak 2022 年 4 月 21 日
I want to outout both a plot that requires two built in functions (plot() and findpeaks() ) and also a matrix that gives the locations, heights, and peak to peak interval. As this function stands, it only outputs the graph. is there anyway to get it to output the matrix as well?
function [myplot,mypeaks,mymatrix] = peaks(d)
myplot = plot(1:length(d), d);
mypeaks = findpeaks(d,'MinPeakDistance',50, 'MinPeakHeight', 10);
[height,locs] = findpeaks(d,'MinPeakDistance',50, 'MinPeakHeight', 10);
pp = [];
for i = 1:length(locs)-1
pp(i) = locs(i+1)-locs(i);
end
pp = [0, pp];
mymatrix = [locs(:), height(:), pp(:)];
end

回答 (1 件)

Sam Chak
Sam Chak 2022 年 4 月 21 日
Remove the semicolon ";" in this line should produce mymatrix on the Command Window.
mymatrix = [locs(:), height(:), pp(:)]

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by