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电子书和数学建模资料

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值