MATLAB Answers

0

contourf min max is it possible?

Asked by Casper Stroem on 10 Oct 2017
Latest activity Commented on by Casper Stroem on 10 Oct 2017

I have a large matrix Cp and using contourf(Cp) Is it possible to mark min and max values in the plot ?

  0 Comments

Sign in to comment.

Tags

4 Answers

Answer by Chad Greene
on 10 Oct 2017

Here's an example you can run. If Cp is a matrix like this:

Cp = peaks(1000); 

and you want to make a contourf plot, specify the values of the contour lines. Here I'm doing -3 to 2 at intervals of 0.75.

contourf(Cp,-3:0.75:2)

  0 Comments

Sign in to comment.


Answer by Walter Roberson
on 10 Oct 2017

[minCp, minidx] = min(Cp(:));
[minrow, mincol] = sub2ind(size(Cp), minidx);
minleg = sprintf('Minima @ (%d,%d) = %.2f', mincol, minrow, minCp);
[maxCp, maxidx] = max(Cp(:));
[maxrow, maxcol] = sub2ind(size(Cp), maxidx);
maxleg = sprintf('Maxima @ (%d,%d) = %.2f', maxcol, maxrow, maxCp);
hold on
lh = plot( mincol, minrow, 'g+', maxcol, maxrow, 'r+', 'MarkerSize', 15);
legend(lh, {minleg, maxleg} );
hold off

  1 Comment

Walter I am getting an error trying your solution

Sign in to comment.


Answer by Casper Stroem on 10 Oct 2017

here is my contour plot 551x49 matrix, and i would like to show min and max value of Cp the exact position on the plot

  0 Comments

Sign in to comment.


Answer by Casper Stroem on 10 Oct 2017

Walter I am getting an error trying your solution

  0 Comments

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today