声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1642|回复: 3

[其他] 大神帮忙分析一下多重分形为程序呗

[复制链接]
发表于 2015-12-15 11:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
有没有用过多重分形为呢,下载了一个程序,看不懂,不会用。大神帮我分析一下呗
clear all
close all;
p1=xlsread('E:matlabdatap1');
p=p1';
C=sum(p);
nn=size(p);
a=length(p);
s=0;
%求kk=[1/a,2/a...1/2,1]
kk=[];
kkk=1/a;
while kkk<=1
     kk=[kk,kkk];
     kkk=kkk*2;
end
for q=-20:4:20
       logyit=[];
       logT=[];
       logXq=[];
       aqfz=[];
       aqfm=[];
%定义了下面两个空集
       fqfz=[];
       fqfm=[];
       for n=1:1:length(kk)
       yit=kk(n);
%计算子集长度T,把3800改为现有数据长度
       T=a*yit;
       P=[];
       X=[];
       for i=1:1:1/yit
          c=p((1+(i-1)*T):(i*T));
          P(i)=sum(c)/C;
          X(i)=[P(i)]^q;
        end
       Xq=sum(X);
       logXq=[logXq,log(Xq)];
       logyit=[logyit,log(yit)];
       logT=[logT,log(T)];
       aqfz=[aqfz sum(X.*log(P))];
       aqfm=[aqfm sum(X)*log(yit)];
       fqfz=[fqfz (q*(sum(X.*log(P)))-sum(X)*log(sum(X)))];
       fqfm=[fqfm sum(X)*log(yit)];
end
s=s+1;
Tq(s)=mean(diff(logXq)./diff(logyit));
aq(s)=mean(diff(aqfz)./diff(aqfm));
fq(s)=mean(diff(fqfz)./diff(fqfm));
plot(logT,logXq,'v-');
hold on
end
figure
plot(aq,fq,'o-');
figure
q=-20:4:20;
%去掉了等号
plot(q,Tq,'x-');

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2015-12-16 09:40 | 显示全部楼层
说明一下什么地方看不懂吧
发表于 2015-12-16 09:42 | 显示全部楼层
我这儿也有一个相关的程序,算多重分形谱的,你可以看看

  1. %%
  2. % Author: Tegy J. Vadakkan
  3. % Date: 09/08/2009
  4. % input a binary image
  5. % the multifractal spectra is calculated based on the ideas in the paper by
  6. % Posadas et al., Soil Sci. Soc. Am. J. 67:1361-1369, 2003

  7. clc;
  8. clear all;
  9. close all;
  10. %%
  11. syms s;
  12. indata=inputdlg({'input photo'});
  13. a = imread(indata{1});
  14. [rows, cols] = size(a);
  15. figure;imshow(a);
  16. npix = sum(sum(a));
  17. %% calculates niL which is the number of pixels in the ith box of size L
  18. % ideas from boxcount.m by F. Moisy have been borrowed here
  19. width = rows;
  20. p = log(width)/log(2);
  21. max_boxes = power(rows,2)/power(2,2);
  22. nL = double(zeros(max_boxes,p));
  23. for g=(p-1):-1:0
  24.             siz = 2^(p-g);
  25.             sizm1 = siz - 1;
  26.             index = log2(siz);
  27.             count = 0;
  28.             for i=1:siz:(width-siz+1)
  29.                 for j=1:siz:(width-siz+1)
  30.                     count = count + 1;
  31.                     sums = sum(sum(a(i:i+sizm1,j:j+sizm1)));
  32.                     nL(count,index) = sums;
  33.                 end
  34.             end
  35. end
  36. %%
  37. qran = 1;
  38. logl = zeros(p,1);

  39. for l=1:p
  40.     logl(l) = log(power(2,l));
  41. end
  42. %% normalized masses
  43. pL = double(zeros(max_boxes,p));
  44. for l=1:p
  45.     nboxes = power(rows,2)/power(power(2,l),2);
  46.     norm = sum(nL(1:nboxes,l));
  47.     if(norm ~= npix)
  48.         display('error');
  49.     end
  50.     for i=1:nboxes
  51.         pL(i,l) = nL(i,l)/norm;
  52.     end
  53. end
  54. %%
  55. %falpha, alpha
  56. for l=1:p
  57.    
  58.     count = 0;
  59.     nboxes = power(rows,2)/power(power(2,l),2);
  60.    
  61.     for q = -qran:+0.1:qran      
  62.         
  63.         %denominator of muiql
  64.         qsum = 0.0;
  65.         for i=1:nboxes
  66.             if(pL(i,l) ~= 0)
  67.                 qsum = qsum + power(pL(i,l),q);
  68.             end
  69.         end

  70.         fqnum = 0.0;
  71.         aqnum = 0.0;
  72.         smuiqL = 0.0;
  73.         for i=1:nboxes
  74.             if(pL(i,l) ~= 0)
  75.                   muiqL = power(pL(i,l),q)/qsum;
  76.                   fqnum = fqnum + (muiqL * log(muiqL));
  77.                   aqnum = aqnum + (muiqL * log(pL(i,l)));
  78.                   smuiqL = smuiqL + muiqL;
  79.             end
  80.         end
  81.         if(uint8(smuiqL)~=1)
  82.             display('error');
  83.         end
  84.         
  85.         count = count + 1;
  86.         fql(l,count) = fqnum;
  87.         aql(l,count) = aqnum;
  88.         qval(count) = q;
  89.     end

  90. end
  91. %%
  92. % alpha_q
  93. for i=1:count
  94.      line = polyfit(logl,aql(:,i),1);
  95.      aq(i) = line(1);
  96.      yfit = polyval(line,logl);
  97.      sse = sum(power(aql(:,i)-yfit,2));
  98.      sst = sum(power(aql(:,i)-mean(aql(:,i)),2));
  99.      ar2(i) = 1-(sse/sst);
  100. end
  101. % f_q
  102. for i=1:count
  103.      line = polyfit(logl,fql(:,i),1);
  104.      fq(i) = line(1);
  105.      yfit = polyval(line,logl);
  106.      sse = sum(power(fql(:,i)-yfit,2));
  107.      sst = sum(power(fql(:,i)-mean(fql(:,i)),2));
  108.      fr2(i) = 1-(sse/sst);
  109. end
  110. figure;plot(qval,aq,'r:o',qval,fq,'g:o');grid on;
  111. h = legend('alpha(q)','f(q)',1);
  112. xlabel('q','FontSize',14);
  113. %gird on;

  114. figure;plot(aq,fq,'r:o');grid on;
  115. xlabel('alpha(q)','FontSize',14);
  116. ylabel('f(q)','FontSize',14);
  117. %%T=fmaxbnd(aq,2.00,4.00);
  118. %xt=solve(aq);
  119. %grid on;
  120. dy=diff(aq);
  121. xz=solve(dy);



  122. line=polyfit(aq,fq,2);
  123. pfit = polyval(line,aq);
  124. figure;plot(aq,fq,'r:o',aq,pfit,'g:o');grid on;
  125. h = legend('f(q)','Parabolic fit to f(q)',3);
  126. xlabel('alpha(q)','FontSize',14);
  127. %grid on;
复制代码
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2015-12-16 22:07 | 显示全部楼层
Vickyvictoria 发表于 2015-12-16 09:42
我这儿也有一个相关的程序,算多重分形谱的,你可以看看

谢谢啦
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-2 17:57 , Processed in 0.211424 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表