【问题标题】:Removing matlab version checking code删除 matlab 版本检查代码
【发布时间】:2023-03-15 08:32:01
【问题描述】:

我最近从 matlab 网站下载了一些代码来使用 octave 运行它。当我尝试运行我创建的 test.m 文件时,该文件会从我收到的下载的源代码文件中调用多个函数:

八度:2> 测试

错误:在第 101 行第 8 列附近未定义“verLessThan”

错误:调用自:

错误:/media/34GB/escola/efficientLBP/assignUserInputs.m 第 101 行第 5 列

错误:/media/34GB/escola/efficientLBP/efficientLBP.m 在第 113 行,第 1 列

错误:/media/34GB/escola/efficientLBP/test.m 第 5 行第 7 列

查看源文件我发现了这段代码

    if isempty(funcParamsNames)
       isNoFuncParamsNames=true;
    else
       if verLessThan('matlab', '7.14') % again, old version do not support 'stable'. 
          funcParamsNames=unique(funcParamsNames); % This can lead to bugs :(
       else
          funcParamsNames=unique(funcParamsNames , 'stable');
       end%
       isNoFuncParamsNames=false;
    end

所以我想知道是否有办法让倍频程来识别这个功能。 感谢您的宝贵时间。

【问题讨论】:

  • Octave 的 unique 类似于 Matlab 的 unique(...,'sorted'),不像 unique(...,'stable'),如您所见 here。如果您需要 'stable' 版本 Octave 检查 this

标签: matlab octave


【解决方案1】:

Octave 似乎知道一个等效函数 unique,但是,我没有看到像 Matlabs 'stable' 这样的选项。

试试独一无二的,看看我猜到了什么?

if isempty(funcParamsNames)
   isNoFuncParamsNames=true;
else
   funcParamsNames=unique(funcParamsNames);       
   isNoFuncParamsNames=false;
end

【讨论】:

    【解决方案2】:

    你可以自己做unique'stable'

    x = rand(1,10);x(5) = x(1);
    % if you have 'stable'
    y1 = unique(x,'stable');
    % if you don't have 'stable'
    [y2,ia] = unique(x);
    [ia,idxs] = sort(ia);
    y2 = y2(idxs);
    % compare
    isequal(y1,y2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      相关资源
      最近更新 更多