Unrecognized function or variable
105 次查看(过去 30 天)
显示 更早的评论
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
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.
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
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!