• Matlab创建文字云


    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

    🍎个人主页:Matlab科研工作室

    🍊个人信条:格物致知。

    更多Matlab仿真内容点击👇

    智能优化算法  神经网络预测 雷达通信  无线传感器

    信号处理 图像处理 路径规划 元胞自动机 无人机

    ⛄ 内容介绍

    ​文字云图在科研中比较少见,但是,在生活中,非常常见,看起来高大上,但是制作起来并不是很难。

    ⛄ 完整代码

    %function [pos LL]=WordCloud

    clear

    close all

    %% make Word Cloud

    % WordCloud

    load('result2.mat');

    display('Done!')

    data{6,1}='天天';

    data{2,1}='Matlab';

    data{18,1}='关注';

    % data{3,2}=1;

    x_std=50;

    y_std=50;

    Max=7.5; 

    Min=2;

    Iteration=500;

    Result.KeyWords=data;

    colors = colormap(cool(length(Result.KeyWords)));

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    alpha=0.01; %learning parameters

    Gamma=1.5;

    Beta=1.3;

    Delta=0.5; % the weight of positive electric charge

    lambda1=0.8; % how much you want to move words to its centre in general

    lambda2=1.2; % how much you want to move the Improtant words to its centre

    % BE AWARE THAT WE USE THE PARAMETER ABOVE IN THE FOLLOWING EQUATIONS!

    % Q_i=(sizes(IX(ii))/Delta)^(Beta)*((word_length(IX(ii))/max(word_length)))^Gamma;

    % Q_j=(sizes(IX(jj))/Delta)^(Beta)*((word_length(IX(jj))/max(word_length)))^Gamma;

    % Q=Q+(Q_i*Q_j/sqrt(dot(g,g)));

    % Q_g=Q_g+g.*(Q_i*Q_j/(dot(g,g)*norm(g)));

    % L(i)=Q+lambda*sum(dot(pos,pos));

    % pos=pos-alpha*(PosG)-alpha*lambda*pos;

    Beta2=0.85; % linearly or unlinearly in the text fontsize...

    %sizes =(freq)^(Beta2) * (Max-Min)+Min; % 

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %Binary=Result.Binary;

    %key_words=results.unique_words;

    key_words=data(:,1);

    for i=1:length(key_words)

        key=key_words{i,1};

        key=key(2:end-1); % stripping off the ' '

        key_words{i,1}=key; 

        clear i

    end

    % check the length of each keywords

    for i=1:length(key_words)

        word_length(i)=length(key_words{i});

        clear i

    end

    %freq=sum(Binary,1)./sum(sum(Binary));

    %freq=results.freq;

    %freq=freq';

    freq=cell2mat(data(:,2));

    freq=freq';

    sizes =(freq.^(Beta2)) * (Max-Min)+Min; 

    pos=randn(length(key_words),2);

    [~,order] = sort(abs(pos(:,1).*pos(:,2)));

    pos = pos(order,:);

    pos(1,:)=x_std.*pos(1,:);

    pos(2,:)=y_std.*pos(2,:);

    for i=1:Iteration

    L=0;

    for ii=1:length(key_words)

        Pos_g=zeros(1,2);

        for jj=1:length(key_words)

            g=pos(ii,:)-pos(jj,:);

            if ii~=jj

            Q_i=(sizes(ii)/Delta)^(Beta)*((word_length(ii)/max(word_length)))^Gamma;

            Q_j=(sizes(jj)/Delta)^(Beta)*((word_length(jj)/max(word_length)))^Gamma;

            L=L+(Q_i*Q_j/(dot(g,g)));

            Pos_g=Pos_g+g.*(Q_i*Q_j/(dot(g,g)*sqrt(dot(g,g))));

            end

        end

        POS_G(ii,:)=Pos_g;

    clear ii

    end

    pos=pos+alpha*POS_G-alpha*(repmat((lambda1+freq'.*lambda2),1,2).*pos);

    L=L+1/2*sum((lambda1+freq'.*lambda2).*(sum(pos.^2,2)));

    LL(i)=L;

    display(sprintf('Iteration %i',i))

    display(sprintf('L is now %i',L))

    clear L

    end

    figure(1)

    subplot(1,2,1)

    plot(pos(:,1),pos(:,2),'b.')

    subplot(1,2,2)

    plot(LL,'-b')

    xlabel('Iteration')

    ylabel('Energy (L)')

    figure(2)

    xlim([-50 50]); % x axis range 

    ylim([-50 50]); % y axis range

    hold on

    for i=1:length(key_words)

        text(pos(i,1),pos(i,2),char(data{i}),'FontSize',sizes(i),'Color',colors(i,:),'HorizontalAlignment','center');

    end

    hold off

    axis off

    ⛄ 运行结果

    数据长这样,自己编一个才有乐趣

    ⛄ 参考文献

    ❤️ 关注我领取海量matlab电子书和数学建模资料

    ❤️部分理论引用网络文献,若有侵权联系博主删除

  • 相关阅读:
    手动实现一个Spring 框架IOC容器
    [maven] 创建 spring boot 项目及使用 Jenkins 运行 maven
    大数据面试SQL(一):合并日期重叠的活动
    osg四元数详解
    vue数据代理、劫持、监视(实现响应式)
    全国大学生数学竞赛(非数学专业)习题精讲等相关资源
    【IDEA设置类注释】设置带作者和日期的类注释+设置方法注释包含返回值类型和参数
    opencv 保存图片imwrite
    ESP8266-Arduino编程实例-BMP388气压传感器驱动
    Win10打开nvidia控制面板闪退怎么解决
  • 原文地址:https://blog.csdn.net/matlab_dingdang/article/details/127463238