您的点赞收藏是我继续更新的最大动力!

一定要点击如下的卡片,那是获取资料的入口!

点击链接加入群聊【2024电工杯】:http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=_PrjarulWZU8JsAOA9gnj_oHKIjFe195&authKey=Sbv2XM853pynlnXiv6M58VOuo6AcFlTrzVAEOxCI6xLmmaLO5sR5wmW5wkzUGoQh&noverify=0&group_code=9653091252024年电工杯数学建模竞赛A题B题思路代码分享-LMLPHPhttp://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=_PrjarulWZU8JsAOA9gnj_oHKIjFe195&authKey=Sbv2XM853pynlnXiv6M58VOuo6AcFlTrzVAEOxCI6xLmmaLO5sR5wmW5wkzUGoQh&noverify=0&group_code=965309125

分享一下2023年电工杯B题第一问数据转换的matlab参考代码,供大家学习:

2024年电工杯数学建模竞赛A题B题思路代码分享-LMLPHP

%% 数据处理,获取更多代码进QQ群:965309125
clc
clear
Data_test = readtable("附件2:调查数据.xlsx");
Data_cell = table2cell(Data_test);
LabelStr = Data_test.Properties.VariableDescriptions;
[m , n] = size(Data_test);
Data_out = zeros(m,n);
Data_out(:,1) = 1:1:m;
%将字符串变量转化为分类变量
for i = 2:22
    DataLabel = Data_cell(:,i);
    DataLabel_cat = categorical(DataLabel);
    DataLabel_int = double(DataLabel_cat);
    Data_out(:,i) = DataLabel_int;
end
mutiStr = {["学习、查资料","浏览新闻","收发邮件","娱乐游戏","聊天交友","资源下载","上网购物","其他"],
    ["真题全面","可以重复学习","资料全面"],
    ["学习的相关经验缺乏","专业疑难问题得不到解决","学习时间安排不充裕","不会正确的学习方法"],
    ["学习效果","学习资源","操作方便","学习费用"],
    ["软件安全级别","网络安全能力","个人信息安全","数据安全","运行安全","服务器安全"],
    ["知识来源的资格审核","知识库的更新频率","是否有定期的审核"],
    ["性能优越","知识面广","运行速度快","稳定","不收费"],
    ["教师传授","课后消化","评价反馈","其他"]};
Data_out2 = Data_out;
Data_muti = cell(m,length(mutiStr));
for i = 1:m
    for j = 1:length(mutiStr)
        strlist = mutiStr{j};
        tempVal = 0;
        tempVal2 = 0;
        tempVal3 = "";
        for k = 1:length(strlist)
            str1 = Data_cell{i,j+23};
            flag = contains(str1,strlist(k));
            if(flag)
                tempVal = tempVal + 2^(length(strlist) - k);
                tempVal2 = tempVal2 + 10^(length(strlist) - k);
            end
            tempVal3 = strcat(tempVal3 ,num2str(flag));
        end
        Data_out(i,j+23) = tempVal;
        Data_out2(i,j+23) = tempVal2;
        Data_muti{i,j} = tempVal3;
    end      
end

%% 导出excel
OutPutTable = array2table(Data_out,'VariableNames',LabelStr);
varTypes = {'double','double','double','double','double','double','double','double',...
    'double','double','double','double','double','double','double','double',...
    'double','double','double','double','double','double','double','string',...
    'string','string','string','string','string','string','string'};
OutPutTable2 = table('Size',[m,n],'VariableNames',LabelStr,'VariableTypes',varTypes);
% OutPutTable2 = array2table(Data_out2,'VariableNames',LabelStr,'VariableTypes',varTypes);
OutPutTable2(:,1:23) = array2table(Data_out(:,1:23));
OutPutTable2(:,24:31) = Data_muti;
writetable(OutPutTable,'调查数据转换.xlsx','Sheet',1,'WriteVariableNames',true);
writetable(OutPutTable2,'调查数据转换.xlsx','Sheet',2,'WriteVariableNames',true);


 

05-11 13:59