Just by changing values of k, the given code gives error. Why?

1 回表示 (過去 30 日間)
Sadiq
Sadiq 2023 年 12 月 22 日
コメント済み: Sadiq 2023 年 12 月 22 日
I changed the values of k in line 7 and it gives error. i don't know why?
clear all;clc
u=[3 4 30 50];% Desired Vector
b=u;
[R,C]=size(b);
P=C/2;
M=2*C;
%k = (1:M).';
k = -(M/2-1):M/2.';
i = (1:P);
xo = sum(1*exp(1i*((k-1).*(-pi/2).*sind(u(P+i))+((k-1).^2.*pi./(16*u(i))).*cosd(u(P+i)).^2)),2);
xe = sum(1*exp(1i*((k-1).*(-pi/2).*sind(b(P+i))+((k-1).^2.*pi./(16*b(i))).*cosd(b(P+i)).^2)),2);
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(xo-xe).^2/(M)

採用された回答

Bruno Luong
Bruno Luong 2023 年 12 月 22 日
編集済み: Bruno Luong 2023 年 12 月 22 日
k need to be column vector and your transposed is miss placed. The correct is
k = -((M/2-1):M/2).';
  3 件のコメント
Bruno Luong
Bruno Luong 2023 年 12 月 22 日
編集済み: Bruno Luong 2023 年 12 月 22 日
Sorry wrong place for open parenthesis, it should be
u=[3 4 30 50];% Desired Vector
b=u;
[R,C]=size(b);
P=C/2;
M=2*C;
k = (-(M/2-1):M/2).'
k = 8×1
-3 -2 -1 0 1 2 3 4
Sadiq
Sadiq 2023 年 12 月 22 日
Thanks a lot dear Bruno Luong for your kind response. Yes, it's working now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by