Index=0:N-1; Hist{2}=log(Index+20)/60; % 15 Hist{2}=Hist{2}/sum(Hist{2}); Hist_cumulation{2}=cumsum(Hist{2}); subplot(3,3,6),stem(0:N-1,Hist{2}),title('log函数变换直方图')
时间: 2023-06-20 15:10:02 浏览: 105
这段代码是在进行直方图处理,将 Index 数组中的每个元素加上 20,然后取对数并除以 60,最后对处理后的数组进行归一化得到 Hist{2} 数组。然后使用 stem 函数将 Hist{2} 数组绘制为一个离散的图像,其中 x 轴为 0 到 N-1,y 轴为 Hist{2} 的值。最后在子图的标题中注明该图是对原始数据进行 log 函数变换后的直方图。
相关问题
I=imread('0294.jpg'); I1=RGB2Lab(I); L1 = double(I1(:,:,1)); L2 = double(I1(:,:,2)); L3 = double(I1(:,:,3)); PL1=mean(L1(:)); PL2=mean(L2(:)); PL3=mean(L3(:)); [m,n]=size(L1); for i=1:m for j=1:n LL1(i,j)=abs(L1(i,j)-PL1); end end for i=1:m for j=1:n LL2(i,j)=abs(L2(i,j)-PL2); end end for i=1:m for j=1:n LL3(i,j)=abs(L3(i,j)-PL3); end end LLL1=reshape(LL1,1,[]); SL1=std(LLL1); LLL2=reshape(LL2,1,[]); SL2=std(LLL2); LLL3=reshape(LL3,1,[]); SL3=std(LLL3); %比较标准差最大 SL=max(max(SL1,SL2),SL3); G = fspecial('gaussian', [5 5], 1); GL1=imfilter(LL1, G, 'circular'); hist=imhist(GL1)/prod(size(GL1)); G1=find(hist); H1=-hist(G1)'*log2(hist(G1)); GL2=imfilter(LL2, G, 'circular'); hist=imhist(GL2)/prod(size(GL2)); G2=find(hist); H2=-hist(G2)'*log2(hist(G2)); GL3=imfilter(LL3, G, 'circular'); hist=imhist(GL3)/prod(size(GL3)); G3=find(hist); H3=-hist(G3)'*log2(hist(G3)); %比较二维熵最小的 H=min(min(H1,H2),H3); if(SL==SL1) ZL=LL1; end if(SL==SL2) ZL=LL2; end if(SL==SL3) ZL=LL3; end if(H==H1) HL=LL1; end if(H==H2) HL=LL2; end if(H==H3) HL=LL3; end %计算初始显著图 C=0.35*ZL+0.65*HL; [Z E]=lrr(C,0.01);%全局低秩Z为低秩部分E为稀疏部分 ZZ=(C-Z).*C; figure,imshow(ZZ,[]);运行代码时报错矩阵维度必须一致。 出错 Untitled3 (line 69) ZZ=(C-Z).*C;如何修正
根据错误提示,矩阵维度必须一致,说明在执行`ZZ=(C-Z).*C`这一行代码时,矩阵C和矩阵Z的维度不同。
在这段代码中,矩阵C的维度是由LL1、LL2、LL3中的一个确定的,而矩阵Z是通过`[Z E]=lrr(C,0.01)`计算得到的,因此可能存在矩阵维度不同的情况。
解决方法是检查矩阵C和矩阵Z的维度,确保它们的维度一致。可以通过使用`size()`函数检查矩阵的维度,或者在调试时查看变量的值,找到维度不同的原因并进行调整。
SNR_dB=20; SNR_linear=10.^(SNR_dB/10.); N_iter=50000; sq2=sqrt(0.5); grps = ['r-'; 'b-';'g-';'p-']; for Icase=1:4 if Icase==1, nT=1; nR=1; % 2x2 elseif Icase==2, nT=2; nR=2; % 4x4 elseif Icase==3,nT=4; nR=4; else nT=8; nR=8; end n=min(nT,nR); I = eye(n); for iter=1:N_iter H = sq2*(randn(nR,nT)+j*randn(nR,nT)); C(iter) = log2(real(det(I+SNR_linear/nT*H'*H))); end [PDF,Rate] = hist(C,50); PDF = PDF/N_iter; for i=1:50, CDF(Icase,i) = sum(PDF([1:i])); end plot(Rate,CDF(Icase,:),grps(Icase,:)); hold on这段代码的原理
这段代码是用来模拟无线通信中的信道容量。它通过生成随机的信道矩阵 H,然后计算该信道矩阵下的信道容量,并对其进行多次重复,最终得到信道容量的概率分布函数(PDF)和累积分布函数(CDF)。其中,信噪比(SNR)是一个关键参数,它用来控制信道的质量。代码中的变量 nT 和 nR 分别代表发射端和接收端的天线数,它们决定了信道矩阵 H 的维度。PDF 和 CDF 的绘制则用来显示不同信道维度下的信道容量分布情况。
阅读全文
相关推荐














