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

2 visualizaciones (últimos 30 días)
Danny
Danny el 15 de Jul. de 2019
Comentada: Danny el 15 de Jul. de 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 comentarios
Stephen23
Stephen23 el 15 de Jul. de 2019
Editada: Stephen23 el 15 de Jul. de 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 el 15 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 15 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by