From: James Tursa on 24 Jun 2010 16:30 And your next question, I suppose, is going to be what about an arbitrary number of 3D matrices? If that is the case, I would suggest using cell arrays and then cell2mat at the end. e.g., X = cell(1,1,5); for k=1:5 X{k} = rand(10,20,k)+k; end C = cell2mat(X); James Tursa
From: Kara Charaziak on 25 Jun 2010 10:45 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i00f8s$i0$1(a)fred.mathworks.com>... > And your next question, I suppose, is going to be what about an arbitrary number of 3D matrices? If that is the case, I would suggest using cell arrays and then cell2mat at the end. e.g., > > X = cell(1,1,5); > for k=1:5 > X{k} = rand(10,20,k)+k; > end > C = cell2mat(X); > > James Tursa Thanks, you are right that the way I decided to use is not very effective (especially that I load a lot of data but still should work - I need to run the whole script only one maybe two times) But I don't know how many rows the new matrix is going to have. Probably sth around 200, but it changes. I used the cat function to merge the 3d matrices: new_data=[]; for i=1:10 [data]=function new_data=cat(3, new_data, data) end so far it seems to work (but I test my script loading only small amount of data) the other issue I was not able to resolve was with adding descriptions to the matrix (strings) so I want to have numbers in matrix but in each row I want to add a string indicating e.g. subject ID (need to be a string) e.g. [20 30 1 2 3 44 5 kk-008] are there such combined matrices? I couldn't find anything helpful so far. Maybe someone has an idea? Thanks for all your help :)
From: us on 25 Jun 2010 11:02 "Kara Charaziak" <pink03(a)o2.pl> wrote in message <i02fe2$coa$1(a)fred.mathworks.com>... > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i00f8s$i0$1(a)fred.mathworks.com>... > > And your next question, I suppose, is going to be what about an arbitrary number of 3D matrices? If that is the case, I would suggest using cell arrays and then cell2mat at the end. e.g., > > > > X = cell(1,1,5); > > for k=1:5 > > X{k} = rand(10,20,k)+k; > > end > > C = cell2mat(X); > > > > James Tursa > > Thanks, > you are right that the way I decided to use is not very effective (especially that I load a lot of data but still should work - I need to run the whole script only one maybe two times) But I don't know how many rows the new matrix is going to have. Probably sth around 200, but it changes. > > I used the cat function to merge the 3d matrices: > new_data=[]; > for i=1:10 > [data]=function > new_data=cat(3, new_data, data) > end > so far it seems to work (but I test my script loading only small amount of data) > the other issue I was not able to resolve was with adding descriptions to the matrix (strings) > so I want to have numbers in matrix but in each row I want to add a string indicating e.g. subject ID (need to be a string) > e.g. [20 30 1 2 3 44 5 kk-008] > are there such combined matrices? I couldn't find anything helpful so far. Maybe someone has an idea? > > Thanks for all your help :) again, most CSSMers would use a CELL approach (as shown above) and do the concatenation in one shot after the loop... us
From: Kara Charaziak on 25 Jun 2010 11:33 "us " <us(a)neurol.unizh.ch> wrote in message <i02gdc$ft4$1(a)fred.mathworks.com>... > "Kara Charaziak" <pink03(a)o2.pl> wrote in message <i02fe2$coa$1(a)fred.mathworks.com>... > > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i00f8s$i0$1(a)fred.mathworks.com>... > > > And your next question, I suppose, is going to be what about an arbitrary number of 3D matrices? If that is the case, I would suggest using cell arrays and then cell2mat at the end. e.g., > > > > > > X = cell(1,1,5); > > > for k=1:5 > > > X{k} = rand(10,20,k)+k; > > > end > > > C = cell2mat(X); > > > > > > James Tursa > > > > Thanks, > > you are right that the way I decided to use is not very effective (especially that I load a lot of data but still should work - I need to run the whole script only one maybe two times) But I don't know how many rows the new matrix is going to have. Probably sth around 200, but it changes. > > > > I used the cat function to merge the 3d matrices: > > new_data=[]; > > for i=1:10 > > [data]=function > > new_data=cat(3, new_data, data) > > end > > so far it seems to work (but I test my script loading only small amount of data) > > the other issue I was not able to resolve was with adding descriptions to the matrix (strings) > > so I want to have numbers in matrix but in each row I want to add a string indicating e.g. subject ID (need to be a string) > > e.g. [20 30 1 2 3 44 5 kk-008] > > are there such combined matrices? I couldn't find anything helpful so far. Maybe someone has an idea? > > > > Thanks for all your help :) > > again, most CSSMers would use a CELL approach (as shown above) and do the concatenation in one shot after the loop... > > us I will try the CELL option (I need to read more about it first), but coming back to the string issue - the string values need to be added much earlier (I mean the function that generates the data need to give such combine matrix - numeric+string and then the loop I showed here will merge matrices generated by the function). So the strings cannot be added as the last step. is sth like that even possible?
From: James Tursa on 25 Jun 2010 12:07 "Kara Charaziak" <pink03(a)o2.pl> wrote in message <i02i7g$g56$1(a)fred.mathworks.com>... > > I will try the CELL option (I need to read more about it first), but coming back to the string issue - the string values need to be added much earlier (I mean the function that generates the data need to give such combine matrix - numeric+string and then the loop I showed here will merge matrices generated by the function). So the strings cannot be added as the last step. > is sth like that even possible? For multiple strings you want to keep track of, each potentially a different length, a CELL approach is usually best. It will definitely be worth your while to learn about cell arrays. James Tursa
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Delaunay/interpolation from triangular mesh Next: Help in some matrix operations |