如何存储生成的值从嵌套在阵列循环,在Matlab? [英] How to store value generated from nested for loop in an array, in Matlab?

查看:128
本文介绍了如何存储生成的值从嵌套在阵列循环,在Matlab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 generated for l, for each iteration, in an array.

当我尝试做类似L(L)= L + sA的;我获得'怪异'的结果。

When I try do something like l(l) = l + sA; I obtain 'weird' results.

请注意:请阅读我的评论贴在下面。谢谢!

NOTE: PLEASE READ MY COMMENTS POSTED BELOW. THANKS!

推荐答案

尝试这样的:

y = find(sA); %This is incredibly strange! What exactly are you trying to achieve with this line?
l = y + sA;

for i=1:10
  l = l + sA;
  StoredL(i, :) = l;
  y = y + length(y); %This line does nothing??? Why is it here?
end

我删除了你内心的循环,因为它是无所事事,对于j = 1将只运行一次有啥意义呢?

I removed your inner loop as it was doing nothing, for j = 1 will only ever run once so what's the point?

这篇关于如何存储生成的值从嵌套在阵列循环,在Matlab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆