Error using .* Matrix dimensions must agree.

조회 수: 10 (최근 30일)
muhammad nur adri nawi
muhammad nur adri nawi 2020년 12월 27일
편집: Image Analyst 2020년 12월 27일
M = 25;
alpha = (M-1)/2;
n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha));
hd(alpha+1)=0;
w_han = '(hann(M))';
h = hd .* w_han; %%%here is the error
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 27일
편집: KALYAN ACHARJYA 2020년 12월 27일
Array multiplication between numeric array and character array??
> whos hd
Name Size Bytes Class Attributes
hd 1x25 200 double
>> whos w_han
Name Size Bytes Class Attributes
w_han 1x9 18 char
Aim?
w_han??
muhammad nur adri nawi
muhammad nur adri nawi 2020년 12월 27일
편집: Image Analyst 2020년 12월 27일
%%% problem this code cannot run
M = 25;
alpha = (M-1)/2;
n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha));
hd(alpha+1)=0;
w_han = '(hann(M))';
h = hd .* w_han.';
[Hr,w,c,L] = Hr_Type3(h);
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)')
subplot(2,2,2);
stem(n,w_han);
title('Hann Window');
axis([-1 M 0 1.2]); xlabel ' n '); ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')
axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)')
w = w'; Hr = Hr';
w = [-fliplr(w), w(2:501)]; Hr = [-fliplr(Hr), Hr(2:501)];
subplot(2,2,4);plot(w/pi,Hr); title('Amplitude Response');grid;
xlabel('frequency in pi units'); ylabel('Hr'); axis([-1 1 -1.1 1.1]);

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

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 12월 27일
편집: KALYAN ACHARJYA 2020년 12월 27일
In this case hd is numeric array with size 25
whos hd
Name Size Bytes Class Attributes
hd 1x25 200 double
Whereas w_han is character array with size 9
>> whos w_han
Name Size Bytes Class Attributes
w_han 1x9 18 char
Once you try to multiply between the numeric array and the character array, you supose to get an error as follows
Error using .*
Matrix dimensions must agree.
If somehow you increase the size of w_han to 25, then no error can occur. Are you really looking for that? In such case it get multiplied with ASCII code of respective character, see the example
>> a='m'
a =
'm'
>> b=5;
>> c=b.*a
c =
545
Here b is multiplied with ASCII code of m, which is 109, as
>> 5*109
ans =
545
I just want to mention this point, so that you can get the idea, if somehow an error cannot occur, it can happen in such a case.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by