Maybe the following sample code could useful.
Up vote 0 down vote favorite share g+ share fb share tw.
I have a matrix which is 36 x 2, but I want to seperate the elements to give me 18, 2 x 2 matrices from top to bottom. E.g. If I have a matrix: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... ... I want to split it into seperate matrices: M1 = 1 2 3 4 M2 = 5 6 7 8 M3 = 9 10 11 12 ..etc. matlab matrix link|improve this question edited Feb 20 at 18:59aganders31,712310 asked Feb 20 at 18:37Awa786122.
– Saphrosit Feb 20 at 18:41 I've tried using linear indexing with things like M(1,1) to extract the the element in row 1 column 1. And also M(1:2), but this extracts first row upto column 2. Whereas I need to extract downwards i.e.
Select a 16 2 x 2 matrices from a 32 x 2 matrix. I suppose I could individually select the 4 elements of the 2 x 2 matrix I want assign them each a variable name and then form the matrix from them, but that would take too long to do for 16 matrices. – Awa786 Feb 20 at 18:51 The answers are too complex except mr_endres' the matrix I have is this: – Awa786 Feb 23 at 12:14.
Maybe the following sample code could useful: a=rand(36,2); b=reshape(a,2,2,18) then with the 3rd index of be you can access your 18 2x2 matrices, eg. B(:,:,2) gives the second 2x2 matrix.
I think that the direct answer to your question is: sampledata = ... 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 1.01 1.02 1.017 1.017 1.018 1.06 1.017 1.018 1.019 1.10 1.11 1.017 1.018 1.019 1.15 1.16 1.017 1.018; ... 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33 0.34 0.35 0.36 1.019 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.01 1.01 1.01 1.02 1.017 1.017 1.018 1.06 1.0175 1.0176; for ix = 1:(size(sampledata,2)/2) assignin('base','M' sprintf('%02d',ix), sampledata(:,ix*2+-1 0)) end This creates 18 variables, named 'M01' through 'M18', with pieces of the sampledata matrix. However, please don't use dynamic variable names like this. It will complicate every other piece of code that it touches.
Use a cell array, a 3D array (as suggested by @Johannes_Endres +1 BTW), or structure. Anything that removes the need for you to write something like this later on: %PLEASE DO NOT USE THIS %ALSO DO NOT BACK YOURSELF INTO A CORNER WHERE YOU HAVE TO DO IT IN THE FUTURE varNames = who('M*'); for ix = 1:length(varNames ) str = 'result(' num2str(ix) ') = some_function(' varNames {ix} ');'; eval(str); end I've seen code like this, and it is slow and extremely cumbersome to maintain, not to mention the headache and pain to your internal beauty-meter.
Also you might consider cell array – Andrey Feb 20 at 19:15.
X = reshape(1:36*2,2 36)' k = 1 for I = 1:2:35 eval(sprintf('M%d = x(%d:%d,:);',k,i,i+1)); k = k+1; end.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.