Code Results?

조회 수: 1 (최근 30일)
zayed
zayed 2011년 12월 14일
Hi,
I have the following code ,but I have a problem in the results,that Mz is just single value 17.619 ,despite it should be a matrix.Also Md is a matrix(1000*1000) but all elements in it has the same value.Can anybody help,please?
clear all;
clc
load lab2_data;
x = radar_noise; % input signal
K = 1000; % K CAPITAL is Block Size
L = length(x) - mod(length(x),K); % only full blocks
zkd = reshape(x(1:L), K, []);
Md=zeros(L,L); % M ZEROS covariance matrix L*L
for i=1:size(zkd,1); % LOOP covariance matrix calculation
Mz=zkd(i,:)*zkd(i,:)';
Md=Md+Mz;
end
Md=Md/K;

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 12월 14일
You duplicate question was answered here:
Walter's:Answer and in another thread that I answered but appears to have been deleted.
  댓글 수: 5
Walter Roberson
Walter Roberson 2011년 12월 14일
Your block size is larger than the number of blocks you have, so LL=length(zkd) is going to return the block size (K) rather than the number of blocks (L) . You then initialize Md to be LL by LL, which is going to be K by K. Your zkd(i,:)*zkd(i,:)' is going to result in L by L, and an L by L matrix is too small to add to a K by K matrix.
Drop the LL=length(zkd); line, and use Md=zeros(L,L)
Remember, length() does not give you the size of the second dimension of an array, it gives you the size of the _largest_ dimension of the array no matter which position it occurs in.
zayed
zayed 2011년 12월 15일
I used Md=zeros(L,L),but the same problem appears ,that Md (5000*5000) with all elements in the matrix equal to11.18040395640934 and Mz is a single value 17.61919686607911 but it should be amtrix
when I changed Mz=zkd(i,:)'*zkd(i,:);the following error appears :
??? Error using ==> unknown
Matrix dimensions must agree.
Error in ==> cov3 at 12
Md=Md+Mz;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by