Risk Matrix in MATlab
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shariful Islam
il 12 Ago 2022
Modificato: Shariful Islam
il 12 Ago 2022
Dear altruist,
I want to create a risk matrix like the attached image. My code is ( I get simmilar types of code from here:How can I create a Risk Matrix Plot? - (mathworks.com)) :
%Define risk matrix 1-3 (1 low - 2 medium - 3 severe)
C=[2 3 3 3 3 3;
2 2 3 3 3 3;
1 2 2 3 3 3;
1 1 2 2 3 3;
0 1 1 2 3 3;
0 0 1 1 2 3];
%Values for each cell
V=[1:5; 6:10; 11:15; 16:20; 21:25]
ax=axes
hold on
%Draw colored grid
[X,Y]=meshgrid(1:size(C,1),1:size(C,2))
h=imagesc(X(:),Y(:),flipud(C))
%Define colors (green, yellow, red)
cmap=[0 1 0;1 1 0;1 0 0];
% Add cell values
str = sprintfc('%d',V(:))
text(X(:),Y(:),str)
% Define row and column labels
RowLabels={'Very unlikely < Once in 100 Years','Unlikely, once in 10 years',
'Uncommon, Once a year', 'Infrequent, once a month', 'Frequent, once a week',
'Very frequent >once a day'};
ColLabels={'Negligible or harmless injury','Injury without reporting sick',
'Recoverable injury, reporting sick <14d', 'Recoverable injury, reporting sick >14d',
'Disability/Death', 'Several deaths/Large hazardous area'};
% Some axes settings
set(gca,'xtick',unique(X),...
'ytick',unique(Y),...
'yticklabels',RowLabels,...
'xticklabels',ColLabels)
% Add colorbar and describe colors
cb=colorbar(ax,'location','southoutside')
set(cb,'ticks',[1.3 2 2.7],...
'ticklabels',{'Low risk','Medium risk','High risk'},...
'ticklength',0)
box on
set(ax,'layer','top')
colormap(cmap)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1096845/image.png)
Could you please tell me, how can I update my code to get this?
0 Commenti
Risposta accettata
Benjamin Thompson
il 12 Ago 2022
This is getting pretty close:
%Define risk matrix 1-3 (1 low - 2 medium - 3 severe)
C=[2 3 3 3 3 3;
2 2 3 3 3 3;
1 2 2 3 3 3;
1 1 2 2 3 3;
0 1 1 2 3 3;
0 0 1 1 2 3];
%Values for each cell
V=1:36;
ax=axes
hold on
%Draw colored grid
[X,Y]=meshgrid(1:size(C,1),1:size(C,2))
h=imagesc(X(:),Y(:),flipud(C))
%Define colors (green, yellow, red)
cmap=[0 1 0;1 1 0;1 0 0];
% Add cell values
str = sprintfc('%d',V(:))
text(X(:),Y(:),str)
% Define row and column labels
RowLabels={"Very unlikely < Once in 100 Years","Unlikely, once in 10 years", ...
"Uncommon, Once a year", "Infrequent, once a month", "Frequent, once a week", ...
"Very frequent >once a day"};
ColLabels={"Negligible or harmless injury","Injury without reporting sick", ...
"Recoverable injury, reporting sick <14d", "Recoverable injury, reporting sick >14d", ...
"Disability/Death", "Several deaths/Large hazardous area"};
% Some axes settings
set(gca,'xtick',unique(X),...
'ytick',unique(Y),...
'yticklabels',RowLabels,...
'xticklabels',ColLabels,...
'XTickLabelRotation', 90,...
'XAxisLocation','top')
% Add colorbar and describe colors
cb=colorbar(ax,'location','southoutside')
set(cb,'ticks',[1.3 2 2.7],...
'ticklabels',{'Low risk','Medium risk','High risk'},...
'ticklength',0)
box on
set(ax,'layer','top')
colormap(cmap)
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!