storing values of for loop in a long function

1 回表示 (過去 30 日間)
Hamish
Hamish 2012 年 7 月 2 日
So I have seen the tutorial on how to save every value of for loop in a matrix
eg:
for i=1:10
y(i)=i+rand
end
However, it doesn't seem to be too straight forward when the result of y is a consequence of a big function. I mean, if the variables a, b, c, d are dependent on i and u (a matrix) is dependent on a, b, c, d and finally y is dependent on u.
How do I solve this issue?
Hope I'm being clear enough. Cheers
  1 件のコメント
Jan
Jan 2012 年 7 月 2 日
編集済み: Jan 2012 年 7 月 2 日
Please post more details, most of all what you have tried so far and which problems occurred. Currently "it doesn't seem to be too straight forward" is not exactly enough to solve your problem.
Actually the solution could be very straight, but I assume, that I simply do not know the problem.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2012 年 7 月 3 日
for i=1:10
a = some function of i
b = some function of i
c = some function of i
d = some function of i
u = some function of a, b, c, d
y(i) = some function of u
end
  2 件のコメント
Jan
Jan 2012 年 7 月 3 日
編集済み: Jan 2012 年 7 月 3 日
Whoops! I've posted nearly same but with rand * i as functions u = [a,b; c,d] and y(i) = trace(u). Has my message been deleted by accident? It is possible, that I've deleted it by myself.
Hamish
Hamish 2012 年 7 月 3 日
Thanks for that. That worked. I guess when I attempted this earlier, there was some other problem due to which I couldn't get the answer.
Simon, I understand I wasn't very specific. But fortunately, I have got the response. The problem was I was confused on whether to write y(i) or/and y(u) at the same time writing a(i), b(i)... This made it quite complicated when the function is very long, more so when there is functions within the function.
Thanks once again for the quick response.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by