Unrecognized function or variable
382 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 13 Apr 2021
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)
Answers (1)
Gargi Patil
on 16 Apr 2021
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 Comment
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!