Unrecognized function or variable
이전 댓글 표시
Hi everyone,
I'm new to MATLAB and I'm trying square a variable, but it doesn't seem to be working (although it does on Python). When I run the code, it gives me an error saying "Unrecognized function or variable 'variableName'", and I can't figure out why.
I'll include a screenshot of the command window as well as the code I've written.
Thanks in advance!
clear all
%declaring variables
rho = 1.22;
c0 = 344;
fillRat = 0.098;
dampRat = 0.03;
Fr = 417;
K = rho*(c0)^2;
Kr = rho*(c0)^2;
H = 0.05;
freqRat = 1.5;
%wall properties
m1 = 1 ; % x - kg
m2 = 1; % x - kg
fDW = (1/(2*pi)) * sqrt((K/H)*((1/m1) + (1/m2)));
fDWSquared = fDW * ((1/(2*pi)) * sqrt((K/H)*((1/m1) + (1/m2))));
%below is the problem line
sqrd = (freqRat)^2;

댓글 수: 3
Walter Roberson
2021년 4월 13일
편집: Walter Roberson
2021년 4월 13일
To verify: did you run whatever .m file that you stored the code in?
By the way: why did you put "clear all" in as part of your code? "clear all" inside a program asks the program to try to do its best to remove all state from MATLAB -- including the state that is recording the fact that the program is running. It is Wile E. Coyote blowing up the bridge that he is standing on, but expecting not to fall down.
Joshua Tshuma
2021년 4월 13일
Walter Roberson
2021년 4월 13일
When you create a .m file, then MATLAB does not execute the code until you say to execute using the green button (or you save the file and invoke it by name in the command line.)
(The workflow is a bit different if you are using LiveScript)
답변 (3개)
Gargi Patil
2021년 4월 16일
Hi,
The given error could not be reproduced. The provided code didn't throw any errors when run on MATLAB Online and successfully assigned the value as follows:
sqrd= 2.2500 % as a double
For further information about this error message and suggestions to resolve it, you can check this thread.
댓글 수: 1
Walter Roberson
2021년 4월 16일
User had not executed the code; see above comments.
Tshiabu Angelus Dan
2023년 5월 16일
% Design the filter
fs = 2*pi*500; % highest significant frequency
Ts1 = 1/fs;
Ts2 = 2*Ts1;
Ts3 = 4*Ts1;
Rp = 2; % passband ripple (dB)
Rs = 12; % stopband attenuation (dB)
Wp = [120 300]*2*pi; % passband frequencies (rad/s)
Ws = [45 450]*2*pi; % stopband frequencies (rad/s)
[n, Wn] = cheby2(n, Rs, Ws/(fs/2)); % determine filter order and cutoff frequency
[b, a] = butter(n, Wn, 'stop'); % design filter coefficients
% Apply the filter to the input signal
t = 0:Ts1:1;
x1 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t); % define input signal
y1 = filter(b, a, x1); % filter input signal
t = 0:Ts2:1;
x2 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t);
y2 = filter(b, a, x2);
t = 0:Ts3:1;
x3 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t);
y3 = filter(b, a, x3);
% Plot filtered signals
figure;
subplot(3,1,1);
plot(t, y1);
title('Filtered Signal (Ts = 1/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,2);
plot(t, y2);
title('Filtered Signal (Ts = 2/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, y3);
title('Filtered Signal (Ts = 4/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
% Sampling period influence
figure;
freqz(b,a);
title('Frequency Response of Filter');
xlabel('Frequency (rad/s)');
ylabel('Magnitude');
% The sampling period does influence the filtering process.
Unrecognized function or variable 'n'.
Error in QUEST2_2 (line 10)
[n, Wn] = cheby2(n, Rs, Ws/(fs/2)); % determine filter order and cutoff frequency
Tshiabu Angelus Dan
2023년 5월 16일
% Design the filter
fs = 2*pi*500; % highest significant frequency
Ts1 = 1/fs;
Ts2 = 2*Ts1;
Ts3 = 4*Ts1;
Rp = 2; % passband ripple (dB)
Rs = 12; % stopband attenuation (dB)
Wp = [120 300]*2*pi; % passband frequencies (rad/s)
Ws = [45 450]*2*pi; % stopband frequencies (rad/s)
[n, Wn] = cheby2(n, Rs, Ws/(fs/2)); % determine filter order and cutoff frequency
[b, a] = butter(n, Wn, 'stop'); % design filter coefficients
% Apply the filter to the input signal
t = 0:Ts1:1;
x1 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t); % define input signal
y1 = filter(b, a, x1); % filter input signal
t = 0:Ts2:1;
x2 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t);
y2 = filter(b, a, x2);
t = 0:Ts3:1;
x3 = 1 + sin(10*pi*t) + sin(200*pi*t) + sin(400*pi*t);
y3 = filter(b, a, x3);
% Plot filtered signals
figure;
subplot(3,1,1);
plot(t, y1);
title('Filtered Signal (Ts = 1/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,2);
plot(t, y2);
title('Filtered Signal (Ts = 2/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3,1,3);
plot(t, y3);
title('Filtered Signal (Ts = 4/(2*pi*500))');
xlabel('Time (s)');
ylabel('Amplitude');
% Sampling period influence
figure;
freqz(b,a);
title('Frequency Response of Filter');
xlabel('Frequency (rad/s)');
ylabel('Magnitude');
% The sampling period does influence the filtering process.
Unrecognized function or variable 'n'.
Error in QUEST2_2 (line 10)
[n, Wn] = cheby2(n, Rs, Ws/(fs/2)); % determine filter order and cutoff frequency
Please fellow can you help me fix this error
카테고리
도움말 센터 및 File Exchange에서 Analog Filters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!