Risk Matrix in MATlab
5 ビュー (過去 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?
0 件のコメント
採用された回答
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)
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!