how to calculate the maximum of a probability array
1 view (last 30 days)
Show older comments
i have such a script where PP_all is a 100651x1 matrix and it derives from this formula
PP_all=1-((1-P_1_4).*(1-P_1_6).*(1-P_1_9).*(1-P_2_2).*(1-P_6).*(1-P_7).*(1-P_8).*(1-P_9 ).*(1-P_10));
at each point of the grid, therefore, the product of these values is displayed.
Now instead, in each point of the grid, I have to visualize the maximum value among all these probabilities that created me PP_all. It is as if they were a series of grids superimposed on each other and in the end, at each point, I only display the maximum value of all and create a new grid.
So I need to obtain another 100651x1 matrix (useful for visualizing the final map) where each point of the grid represents the maximum value among all the probabilities P_1_4, P_1_6,P_2_2...P_10.
Can anyone help me?
longrd=0:0.1:40;
latgrd=30:0.1:55;
limlon=[min(longrd),max(longrd)];
limlat=[min(latgrd),max(latgrd)];
ic=0;
for i=1:length(longrd)
for j=1:length(latgrd)
ic=ic+1;
lonlatgrd(ic,1)=longrd(i);
lonlatgrd(ic,2)=latgrd(j);
end
end
figure()
for i=1:length(longrd)
for j=1:length(latgrd)
XX(i,j)=longrd(i);
YY(i,j)=latgrd(j);
isel1=find(lonlatgrd(:,1)==longrd(i));
isel2=find(lonlatgrd(isel1,2)==latgrd(j));
isel=isel1(isel2);
ZZ(i,j)=PP_all(isel));
end
end
contourf(XX,YY,ZZ,500,'linecolor','none');
colormap jet
hold on
load coastlines.mat;
xlim([min(longrd), max(longrd)]);
ylim([min(latgrd), max(latgrd)]);
colorbar;
pbaspect([1 1 1]);
2 Comments
Edoardo_a
on 13 Mar 2023
Edited: Edoardo_a
on 13 Mar 2023
Could you upload the 'PP_all' function?
If I am right, you would like to plot not the PP_all value, but the highest value among the different P_x that are used to calculate PP_all?
I think it would be easier to get what you need by modifying the function directly.
Accepted Answer
Voss
on 13 Mar 2023
PP_temp = [P_1_2, P_1_6, P_1_9, P_2_2, P_6, P_7, P_8, P_9, P_10];
PP_max = max(PP_temp,[],2);
0 Comments
More Answers (0)
See Also
Categories
Find more on Colormaps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!