matrix points from a plot

Hello!
I got this code below thtr plot some profiles and her maximun value.
I want to have a matrix with the location of the max values for plot it with other varibles.
I mean something like:
Profile max_value depth_location
1 x.xx 15cm
2 x.xxx 10cm
3 x.xxx 20cm
....
[depht_maxvalue] = 15 10 20 ...
load 'biom.txt' % (Fortran file output)
tl=201; % Number of depth levels
[m,n]=size(biom); % derermining the size of the data
mm=m/tl; % total number of profiles
% sm=mm; % tottal profiles (for last profile); sm=mm-19; $for all profiles
% maxDepth = -400;
x= 1e6*biom; % <-- here variable concentration microMole => 1e9 miliMol=>1e6
% nexttile %biom
% for i=sm:mm
for i = 1:mm
% d=maxDepth ;
hold on
plot(( x ((i-1)*tl+1:(i-1)*tl+tl,1)), (-biom((i-1)*tl+1:(i-1)*tl+tl,2)), 'k', 'LineWidth',1.0)
[x_max,idx] = max(x((i-1)*tl+1:(i-1)*tl+tl,1));
plot(x_max,-biom((i-1)*tl+idx,2),'ro')
end
ylim([-50 -10])
xlabel ({'B' ; '(10^6 cells cm^-^2)'}) %label for variable and units
ylabel ({'Depth' ;'(cm)'})
set(gca,'XAxisLocation','top')

Answers (2)

What you are trying to attain is to display the found max value and depth location to be displayed in the simulation order:
...
fprintf('Profile max_value depth-location \n')
for i = 1:mm
plot(x((i-1)*tl+1:(i-1)*tl+tl,1), -biom((i-1)*tl+1:(i-1)*tl+tl,2), 'k', 'LineWidth',1.0), hold on
[x_max,idx] = max(x((i-1)*tl+1:(i-1)*tl+tl,1));
plot(x_max,-biom((i-1)*tl+idx,2),'ro')
fprintf('%d %10.3f %10.0f cm \n',[i, x_max, biom((i-1)*tl+idx,2)])
end
...
The below includes code for making such a matrix and also a table of the same information (take whichever is more useful):
load 'biom.txt' % (Fortran file output)
tl=201; % Number of depth levels
[m,n]=size(biom); % derermining the size of the data
mm=m/tl; % total number of profiles
summary_matrix = zeros(mm,3);
summary_table = table( ...
zeros(mm,1),zeros(mm,1),zeros(mm,1), ...
'VariableNames',{'Profile' 'max_value' 'depth_location'});
x = 1e6*biom; % <-- here variable concentration microMole => 1e9 miliMol=>1e6
hold on
for i = 1:mm
plot((x((i-1)*tl+1:(i-1)*tl+tl,1)),(-biom((i-1)*tl+1:(i-1)*tl+tl,2)),'k','LineWidth',1.0)
[x_max,idx] = max(x((i-1)*tl+1:(i-1)*tl+tl,1));
depth_of_max = biom((i-1)*tl+idx,2); % depth is positive in the summary matrix/table
plot(x_max,-depth_of_max,'ro') % and plotted negative
summary_matrix(i,:) = [i x_max depth_of_max];
summary_table(i,:) = {i x_max depth_of_max};
end
ylim([-50 -10])
xlabel ({'B' ; '(10^6 cells cm^-^2)'}) %label for variable and units
ylabel ({'Depth' ;'(cm)'})
set(gca,'XAxisLocation','top')
disp(summary_matrix);
1.0e+03 * 0.0010 0.0001 0 0.0020 0.0001 0.0007 0.0030 0.0007 0.1254 0.0040 0.0023 0.1204 0.0050 0.0042 0.1129 0.0060 0.0060 0.1029 0.0070 0.0076 0.0929 0.0080 0.0092 0.0804 0.0090 0.0110 0.0629 0.0100 0.0159 0.0454 0.0110 0.0319 0.0304 0.0120 0.0824 0.0204 0.0130 0.1975 0.0150 0.0140 0.6344 0.0132 0.0150 1.0471 0.0144 0.0160 1.4309 0.0150 0.0170 1.8585 0.0156 0.0180 2.0602 0.0162 0.0190 2.0714 0.0168 0.0200 2.0328 0.0174
disp(summary_table);
Profile max_value depth_location _______ _________ ______________ 1 0.1 0 2 0.10042 0.7 3 0.7237 125.4 4 2.2508 120.4 5 4.1584 112.9 6 5.988 102.9 7 7.619 92.9 8 9.1548 80.4 9 11.024 62.9 10 15.928 45.4 11 31.875 30.4 12 82.383 20.4 13 197.49 15 14 634.44 13.2 15 1047.1 14.4 16 1430.9 15 17 1858.5 15.6 18 2060.2 16.2 19 2071.4 16.8 20 2032.8 17.4

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2022a

Tags

Asked:

on 24 Jun 2022

Answered:

on 24 Jun 2022

Community Treasure Hunt

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

Start Hunting!