Trying to run a script many times and combine all the results

1 回表示 (過去 30 日間)
Danny
Danny 2019 年 7 月 15 日
コメント済み: Danny 2019 年 7 月 15 日
I have a script which takes a random matrix does some calculations on it and then I am interested in looking at the eigenvalues. At the end of my script I get the eigenvalues using e=eig(A) but I want to run this 100s of times and collect and the eigenvalue to plot them on a graph.
I can write for k=1:100 but then e will only give me the eigenvalues for the last calculation as it overwrites e each time, so I think I'm looking for either a way of saying e_k=eig(A) so it will return e_1 e_2 .... or some way of combining them in the script itself so it automatically put them together.
  2 件のコメント
Stephen23
Stephen23 2019 年 7 月 15 日
編集済み: Stephen23 2019 年 7 月 15 日
"...so it will return e_1 e_2 ...."
Putting numbers into variable names is a sign that you are doing something wrong.
"..or some way of combining them ..."
Sure that is easy using indexing, either with a numeric array or a cell array: which class would you prefer the output to be?
Danny
Danny 2019 年 7 月 15 日
I think I would be looking for a numeric array as what am I looking for is essentially just a list of all the eigenvalues together, I'm not worried about ordering them in any way.

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

採用された回答

Jan
Jan 2019 年 7 月 15 日
eList = cell(1, 100);
for k = 1:100
callYourScript;
eList{k} = e;
end
A cell array is useful, if the elements, here e, have different sizes or types. If all e are vectors of the same length, a numerical array is usually more efficient:
eList = zeros(n, 100); % where n is the length of e
for k = 1:100
callYourScript;
eList(:, k) = e;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by