Risk Matrix in MATlab

2 次查看(过去 30 天)
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?

采纳的回答

Benjamin Thompson
Benjamin Thompson 2022-8-12
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)

更多回答(1 个)

Shariful Islam
Shariful Islam 2022-8-12
编辑:Shariful Islam 2022-8-12
@Benjamin Thompson,thanks a lot :D
But how can I add 0, 1, 2 3,.... , move low risk to the middle and C matrix was different value

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by