Risk Matrix in MATlab
6 views (last 30 days)
Show older comments
Shariful Islam
on 12 Aug 2022
Edited: Shariful Islam
on 12 Aug 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)
Could you please tell me, how can I update my code to get this?
0 Comments
Accepted Answer
Benjamin Thompson
on 12 Aug 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 Comments
More Answers (1)
See Also
Categories
Find more on Financial Toolbox 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!