【问题标题】:how to iterate through a column vector and output the results into another column vector如何遍历列向量并将结果输出到另一个列向量
【发布时间】:2017-02-24 17:55:43
【问题描述】:

我有一个大的列向量,我想遍历它并制作另一个列向量,但我只得到循环的最终值。

function[c]=height(n)
[x,y]=re(0,0.09,0.02,0.1,n); 
for i=1:length(y)
    while (i) < (n-1)/2)
    c=[(y(i)-y(101-i))];
    end
end

如何将 c 作为列向量?

【问题讨论】:

  • 你没有使用你的迭代器来索引c
  • 你发布了整个代码吗? while 语句中缺少 )。此外,iwhile 循环中没有被修改(这很好,因为它是外部for 循环的迭代器)这意味着while 循环中的代码可以不执行或无限执行自从n 未修改以来的次数..

标签: matlab loops for-loop vector


【解决方案1】:

你需要告诉 Matlab c 是一个向量。一种方法是将循环内的操作结果分配给 c(i)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2022-11-02
    • 2015-10-07
    • 1970-01-01
    相关资源
    最近更新 更多