matlab关于绘图问题

这是数学建模topsis部分的代码,画图部分为了得到想要的图形,查了不少资料,记录一下。

clc;
clear all;
% Taking the input method to initialize the marix

%disp('Input metrix please:');
%X=input('X=');
X=[50.8 4.3 8.7;200.0 4.9 7.2;71.4 2.5 5.0;98.5 3.7 2.7;10.2 2.4 0.3];
% Geting the rows and columns of the matrix
[n,m]=size(X);
% A special way to format and display data
%disp(['There are ' num2str(n) ' evaluation indexes and ' num2str(m) ' evaluation objec']);
% Directly forward data without judgement
%Position=input('Input the column of indictor to be forword processed. For example, columns 2, 3 and 6, enter [2,3,6] please!');
% As we know, the lower the 3 indictors, the batter. All of the are miniature indector.

% Convert minimum to maximum
posit_x=max(X)-X;
disp('After forwarding, the matrix is: ');
disp(posit_x);

% Add the weight to the caculation results
weight = 1/m;
% Normalize the forward matrix
Z=posit_x./repmat(sum(posit_x.*posit_x).^0.5,n,1);
disp('The normalized matrix is:');
disp(Z);

% Calculating the distance from the maximum and the minimum, and calculating the score
D_P=sum([(Z-repmat(max(Z),n,1)).^2].*repmat(weight,n,1),2).^0.5;
D_N=sum([(Z-repmat(min(Z),n,1)).^2].*repmat(weight,n,1),2).^0.5;
S=D_N./(D_P+D_N);
disp('The final score is:(the higher the score, the greater the safety factor!)');
stand_S=S/sum(S);
% [sorted_S,index = sort(stand_S);
% index is the location of the elements in sorted_S
% disp(sorted_S);
disp(stand_S);
% disp('The security ranking of these factories is: ');
% disp();
All_value={'白沙湘水','沈阳田师傅','抚顺龙凤','大同同家山','扎诺尔南山'};
valueset={'白沙湘水','沈阳田师傅','抚顺龙凤','大同同家山','扎诺尔南山'};
x_g=categorical(All_value,valueset,'Ordinal',true);

b=bar(x_g,stand_S);
title('各煤矿厂安全系数得分情况');
for i = 1:5 
%    text(x_g(i),stand_S(i)+0.001,num2str(stand_S(i))),'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',8,'FontName','Times New Roman')
    text(x_g(i),stand_S(i)+0.001,num2str(stand_S(i)),'HorizontalAlignment','center','VerticalAlignment','bottom','FontSize',8,'FontName','Times New Roman')
end;

运行结果如下图所示:
在这里插入图片描述
另外所绘的图如下:
在这里插入图片描述
注:

All_value={'白沙湘水','沈阳田师傅','抚顺龙凤','大同同家山','扎诺尔南山'};
valueset={'白沙湘水','沈阳田师傅','抚顺龙凤','大同同家山','扎诺尔南山'};
x_g=categorical(All_value,valueset,'Ordinal',true);

这是用来规定数组的顺序的,不然categorical会按照自己的规则来进行排序;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值