How to extract the maximum value of an area of a figure?

2 views (last 30 days)
I have a figuret that I want to extract the maximum value fro
m a particular area on the plot from. I am quite new to matlab and have searched online for help but cannot find a way round this problem.
My current code to extract the area I want is
% Load file
load opfile.mat
% open figure
open opfile.fig
hold on
fig = gcf;
zoomedpoint = rectangle('Position',[491075 492065 4384740 4385580]);
axis([491075 492065 4384740 4385580]);
% Save the plot
saveas(gcf, 'zoomedpoint.fig')
This produces a figure of the selcted area but I cannot seem to extacct the maximum value from this.
I have also tried using the below lin eof code; however, when entered it comes up with the below error, despite these being the values I used to create the figure.
"Index in position 1 exceeds array bounds. Index must not exceed 988.
Error in Fig4_analysis (line 24)
mHs = max(hrms(491075:492065,438474:438558));"
mHs = max(hrms(491075:492065,438474:438558));
Any help would be very much approcated. Thank you
  1 Comment
Image Analyst
Image Analyst on 5 Jul 2022
You forgot to attach 'opfile.mat'. Can you use the paperclip icon to attach it?
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Sign in to comment.

Answers (1)

Mathieu NOE
Mathieu NOE on 5 Jul 2022
so your data is a matrix (hrms)
what is the dimension of hrms ? you are probably confused between the range of that you want to display (hrms) and the size of the data , which is generating the error
So it may be worth to share as well the mat & fig files along with your code.
FYI , you can find the row and column index of the max value by this method :
  • here in my example the data matrix is A
  • M is the max value of A and row and col are the x, y indexes of the max value (if you need them)
  • of course , M = A(row,col) , you can double check !
A = [1 2 3; 7 8 9] % dummy data matrix
[M,ind] = max(A,[],'all','linear') % max value of matrix
[row,col] = ind2sub(size(A),ind) ; % Convert linear indices to subscripts
So , in your code , you can do :
A = hrms(491075:492065,438474:438558); % !! check for indexes here !!
[M,ind] = max(A,[],'all','linear') % max value of matrix
[row,col] = ind2sub(size(A),ind) ; % Convert linear indices to subscripts




Community Treasure Hunt

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

Start Hunting!