How to fit a line through all tops of a graph?

조회 수: 2 (최근 30일)
Christian Klinkenberg
Christian Klinkenberg 2018년 9월 20일
답변: Zenin Easa Panthakkalakath 2018년 9월 25일
Up to now I have the following MATLAB script:
%% clear; clc; close all for i = (6:21) %go through all measurement files and load data into matrix measurement{i} = dlmread(['Measure',num2str(i),'.txt']); %load measurement data hold on plot(measurement{i}(:,2)) %plot all measurements end
lgd = legend('Measurement 1','Measurement 2','Measurement 3','Measurement 4','Measurement 5','Measurement 6','Measurement 7','Measurement 8','Measurement 9','Measurement 10','Measurement 11','Measurement 12','Measurement 13','Measurement 14','Measurement 15','Measurement 16') lgd.FontSize = 7; xlim([1800 5000]) xlabel('Number of measurement') ylabel('Voltage (V)')
See appendix for an example of such as graph where I want a line through the maxima points

답변 (1개)

Zenin Easa Panthakkalakath
Zenin Easa Panthakkalakath 2018년 9월 25일
In order to find the local maxima, there is a function by the name 'findpeaks'. Refer to the link below for the documentation:
In order to draw the line, just use the 'plot' function. If the coordinate of the local maximum is (x_max, y_max), then the plot command should be something like this:
plot([0 x_max], [y_max, y_max]);

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by