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

1 vue (au cours des 30 derniers jours)
Danny
Danny le 15 Juil 2019
Commenté : Danny le 15 Juil 2019
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 commentaires
Stephen23
Stephen23 le 15 Juil 2019
Modifié(e) : Stephen23 le 15 Juil 2019
"...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 le 15 Juil 2019
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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 15 Juil 2019
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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by