✅作者简介:热爱科研的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
⛄ 运行结果
数据长这样,自己编一个才有乐趣