How to store value generated from nested for loop in an array, in Matlab?

前端 未结 2 694
我寻月下人不归
我寻月下人不归 2021-01-27 13:38
y = find(sA);
l = y + sA;

for i=1:10
  for j=1
      l = l + sA;
  end
  y = y + length(y);
end

I would like to know how to store the value that is ge

2条回答
  •  长情又很酷
    2021-01-27 14:27

    For a complex loop, usually I do something like this:

    results = zeros(expectedLength,1);
    ixNextResult = 1;
    
    for ixForLoop1 = 1:10
        for ixForLoop2 = 20:30
            ..
            results(ixNextResult) = calculationResult;
            ixnextResult = ixNextResult + 1;
        end
    end
    

    I'm having a hard time understanding what your code is trying to accomplish, so I'm not sure what to change. For example the snippet l(l) = l+sA does not make a lot of sens to me.

提交回复
热议问题