【问题标题】:Loop/Recurse in MatLabMatLab 中的循环/递归
【发布时间】:2018-11-17 20:11:36
【问题描述】:

刚开始自学 MatLab(python 背景),我只想遍历一个简单的函数输出列表。例如,我将 F1 到 F7 作为 7 个不同函数的输出,我想将它们放在一个列表中并返回该列表中的最小输出值。我该怎么做呢?我知道 MatLab 使用数组而不是列表,只是不确定从哪里开始。提前致谢。

【问题讨论】:

    标签: matlab list loops recursion


    【解决方案1】:

    Matlab 的基本数据类型是矩阵,可以是任意维数组。这里没有像list 这样的python,您可以执行以下操作来实现您的要求。

     % Let's say you've value through F1 through F7
    
     data = [F1 F2 F3 F4 F5 F6 F7];  % creating matrix with the value F1 through F7
     min_value = min(data);
     disp(min_value);
    

    你也可以在老式的loop 结构中做到这一点。

    % Let's say you've value through F1 through F7
    
     data = [F1 F2 F3 F4 F5 F6 F7];  % creating matrix with the value F1 through 
     F7
     min_value = intmax;
     for i =1:7
        if(min_value > data(i))
           min_value=data(i);
        end
     end
     disp(min_value);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-27
      • 2017-01-21
      • 2014-08-23
      • 2020-04-04
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 2011-02-09
      相关资源
      最近更新 更多