简体   繁体   English

Octave中的交易功能不起作用

[英]deal function in Octave not working

I've got a .m file that was written (and works) when run in Matlab, but when I go to run it in Octave, I get an error. 我有一个.m文件在Matlab中运行时编写(和工作),但是当我在Octave中运行它时,我收到一个错误。 I know the two programs have their differences, I just don't know quite how to re-write the problematic line of code to make it work. 我知道这两个程序有不同之处,我只是不知道如何重新编写有问题的代码行以使其工作。

Here's the code. 这是代码。 The final line is the one that's causing the problems: 最后一行是导致问题的那一行:

dirr = '/my/file/path/'
foldlist = dir([dirr '*.wav']);
foldname={};
[foldname{1:length(foldlist),1}] = deal(foldlist.name)

And here's the error that comes when run: 这是运行时出现的错误:

error: Invalid call to deal.  Correct usage is:
-- Function File: [R1, R2, ..., RN] = deal (A)
-- Function File: [R1, R2, ..., RN] = deal (A1, A2, ..., AN)

Seems simple enough, given the error explanation, I just don't know how to re-write it. 看起来很简单,给出错误解释,我只是不知道如何重写它。

You should be able to do this: 你应该能够做到这一点:

foldname={foldlist.name};

This would be the better approach in MATLAB as well. 这也是MATLAB中更好的方法。

foldlist.name is a comma-separated list of values. foldlist.name是以逗号分隔的值列表。 These are captured in a cell array by putting the curly braces around it. 通过在其周围放置花括号,将它们捕获在单元阵列中。 Equivalent to {a,b,c} . 相当于{a,b,c}

The problem with the original code is that, after initializing foldname={} , the indexing foldname{1:length(foldlist),1} is illegal. 原始代码的问题在于,在初始化foldname={} ,索引foldname{1:length(foldlist),1}是非法的。 MATLAB tends to add empty cells when indexing out of bounds on the left-hand-side of an assignment. 当索引超出赋值左侧的边界时,MATLAB倾向于添加空单元格。 Octave does too, but here there are square brackets around the indexed array, and it seems that Octave doesn't parse this particular bit in the same way. Octave也是如此,但是索引数组周围有方括号,似乎Octave没有以相同的方式解析这个特定的位。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM