Breaking up a matrix/array
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Andrew Kreitzman
el 24 de Jun. de 2013
Comentada: Megan Renny
el 10 de Jul. de 2018
I am running a regression of some global equity data over various style factors, however my return data is conglomerated into one 30,000x2 matrix....One column is the "country code) of the security and the other is the return(obviously). Is there a way to break up this returns matrix into many smaller matrices based on the country.I thought about using a for loop with an if statement like: for i = 1:length(country_codes) if country_codes(i) == country_codes(i+1)
And then I get stuck....it doesnt seem reasonable to use a for loop where I will be creating a new matrix inside the loop, possily breaking out of the loop to store the matrix, and then starting where I left off. There are about 50 countries, so you can see how this would be terribly inefficient (if at all possible). Also, ideally I would store the indices of the new arrays of country codes so that I could use these indices to concatenate the new country code and return arrays with the corresponding style factor weights and industry code data for the regression. Hopefully someone has a good idea! Thanks!
0 comentarios
Respuesta aceptada
Iain
el 24 de Jun. de 2013
codes = matrix(:,1);
code_list = unique(codes);
for i = 1:numel(code_list)
new{i} = matrix(code_list(i) == codes,:);
end
6 comentarios
Megan Renny
el 10 de Jul. de 2018
Hello, I have a similar issue. I have a program that reads in data and creates a vertical cell of matrices. The cell will not always be the same height when this function is used. I am trying to find out how to create another script or function that will simply pull out each array out of the cell, and make it its own variable. I have seen that there are a lot of "incorrect" ways to do this, but I am only trying to use this to read in data in an easily plotted way.
Ie. The raw txt file will have 6 columns and a many rows. The first program a friend wrote identifies the beginning and end of each experimental run and divides this into multiple arrays that are stored in a common cell that has a height equal to the number of experiment's I've done. Each array may have a different height.
I want to now have each array, or element of the cell, be its own variable. How might this be done? Thank you in advance for your kind response.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!