I have a matlab plot(graph) x,y axis and i want to find the maximum from x axis. How to find that?

5 views (last 30 days)
a= [1 2 13 20 10 20 12 1 13 14]
b= [1:10:100]
plot(a,b)
I want to find the maximum('a') from the plot and then take the corresponding point let say 'a3,b3' and store it some where else and remove it from the plot. then I want to subtract 'a3' from every point left in 'a' and plot the graph. and I need to do this again till it reaches an thresh hold point.

Accepted Answer

Image Analyst
Image Analyst on 31 May 2015
Try this demo and see if it does what you want (plotting, finding, saving, and removing max, then subtracting max from what's left).
fontSize = 24;
a= [1 2 13 20 10 20 12 1 13 14];
b= [1:10:100];
storedMaxima = zeros(1, length(a));
loopCounter = 1; % For storing the maxima
hFig = figure;
while ~isempty(a)
% Plot what we have.
plot(b, a, 'b*-', 'MarkerSize', 19, 'LineWidth', 2);
grid on;
xlabel('b', 'FontSize', fontSize);
ylabel('a', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% See if they want to quit now.
if length(a) > 1
promptMessage = sprintf('Do you want to Continue processing,\nor Quit?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(button, 'Quit')
break;
end
end
% Find the max
[maxValue, indexOfMax] = max(a);
% Store the maxima
storedMaxima(loopCounter) = maxValue;
loopCounter = loopCounter + 1;
% Remove the max
a(indexOfMax) = [];
b(indexOfMax) = [];
% Subtract the max from a.
a = a - maxValue;
end
% Print maxima to command window:
storedMaxima
uiwait(helpdlg('Done with demo.'));
close(hFig); % Close down figure.
  3 Comments
Image Analyst
Image Analyst on 1 Jun 2015
Edited: Image Analyst on 1 Jun 2015
It looks like a different CLEAN algorithm than the famous one used in astronomy, but good luck with it. Let us know if you have any questions.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!