简体   繁体   English

八度错误:无法读取.m文件中的变量

[英]Octave error: can't read a variable in .m file

I have a 'data' file, 'lab1.m' in my working directory. 我的工作目录中有一个“数据”文件“ lab1.m”。 Here the content of them. 这里是他们的内容。

data: 数据:

0 1 2 3 4 0 1 2 3 4

2 0 9 2 7 2 0 9 2 7

5 6 3 4 7 5 6 3 4 7

lab1.m: lab1.m:

load data
function y = RSSI_to_dBm(x, z)

    y = data(z, x);

end

However, there's an error when I call RSSI_to_dBm(2, 2): 但是,当我调用RSSI_to_dBm(2,2)时出现错误:

octave:30> RSSI_to_dBm(2, 4) 八度:30> RSSI_to_dBm(2,4)

error: `data' undefined near line 3 column 6 错误:第3行第6列附近的“数据”未定义

error: called from: 错误:来自:

error: RSSI_to_dBm at line 3, column 4 错误:第3行第4列的RSSI_to_dBm

How can I solve it? 我该如何解决? And how can I load 'data' to a variable name such as 'A'? 以及如何将“数据”加载到变量名称(例如“ A”)中? Thank you for answering. 感谢您的回答。

I'm a bit confused as well, but I would look into this: 我也有些困惑,但是我会调查一下:

"error: `data' undefined near line 3 column 6" “错误:“数据”在第3行第6列附近未定义”

Because you only have 5 columns in your data array, but the error is referring to column 6. 因为您的数据数组中只有5列,但是错误是指第6列。

Find column 6 and you may find your problem. 找到第6列,您可能会发现问题。 Make sure the dimensions of the data matrix match the dimensions that the "x" and "z" parameters take. 确保数据矩阵的尺寸与“ x”和“ z”参数所采用的尺寸匹配。 If they are askew, this can cause problems in MATLAB. 如果它们歪斜,可能会在MATLAB中引起问题。 I've found it easiest to monitor the dimensions of my matrices by using the debugger. 我发现使用调试器监视矩阵的尺寸最容易。

Hope that helps you in the right direction. 希望能帮助您朝正确的方向发展。

The problem is that data is being interpreted as a variable name, but there is no variable called data . 问题在于data被解释为变量名,但是没有名为data变量。 The problem is easily solved by putting the file name in quotes: 通过将文件名放在引号中可以轻松解决该问题:

load "data";

You might need to specify the file extension, and you can assign the result to a variable in the usual way: 您可能需要指定文件扩展名,然后可以按照通常的方式将结果分配给变量:

A = load "data.txt";

I have tried out a solution: 我已经尝试了一种解决方案:

load data
function z = RSSI_to_dBm(x, y, data)

    z = data(x, y);

end

It works by passing the "data" to the function every time I call it. 每次我调用它时,都会通过将“数据”传递给函数来工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 倍频程变量定义错误 - Octave variable definition error Octave从另一个m文件调用函数 - Octave calling function from another m file JavaScript无法读取function()中的变量 - Javascript can't read variable in function() 无法使用 [BlobInput] 读取 .xlsx 文件 - Can't read an .xlsx file with [BlobInput] 如何调试错误此文件“compiler.py”,第 8 行 f(n, m+1) = f(n-1, m) + f(n, m) + f(n+1, m) ^ SyntaxError:无法分配给 function 调用 - How to debug error this File “compiler.py”, line 8 f(n, m+1) = f(n-1, m) + f(n, m) + f(n+1, m) ^ SyntaxError: can't assign to function call 可以在shebang可执行GNU Octave文件中定义函数吗? - Can functions be defined within a shebang executable GNU Octave file? 倍频程函数定义错误 - Octave function definition error Excel + VBA +编译错误AutoOpenRequiredWorkbook(myFileNameToOpen,myFilePath)无法弄清楚为什么我得到此错误 - excel + vba + compile error AutoOpenRequiredWorkbook (myFileNameToOpen, myFilePath) can't figure out why I'm getting this error 在外部 js 文件中找不到变量:function 名称 - can't find variable: function name in external js file 无法在txt文件中的getline(cin,(variable))之后删除nextline - Can't delete nextline after getline(cin , (variable)) in a txt file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM