MATLAB Answers

# Unrecognized function or variable

418 ビュー (過去 30 日間)
Joshua Tshuma 2021 年 4 月 13 日
コメント済み: Walter Roberson 2021 年 4 月 16 日
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 件のコメント表示非表示 2 件の古いコメント
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)

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

### 回答 (1 件)

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.

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

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by