From: Ben Williams on 2 Jun 2010 11:08 Hello, I woudl like to know how to use the element values within an array as the index values of another array: For example: address = [1,4,22,34,35,36,37,48] Each of the the element values in the above array correspond to a cell address where the data satisfies a given condition. e.g. data{1},data{4},data{22},data{34}... etc all satisify a given condition. What I would like to be able to do is obtain an average of data{1}, data{4}, data{22}... etc but I would like to do it in such a way that I don't have to manually type in the address, instead I can simply have a formula that automatically retrives all the data{j} for all the elements j in the address array. Any ideas? Thanks, Ben
From: Luca Zanotti Fragonara on 2 Jun 2010 11:18 "Ben Williams" <benjamin.williams(a)remove.this.plymouth.ac.uk> wrote in message <hu5s4k$ali$1(a)fred.mathworks.com>... > Hello, > > I woudl like to know how to use the element values within an array as the index values of another array: > > For example: > > address = [1,4,22,34,35,36,37,48] > > Each of the the element values in the above array correspond to a cell address where the data satisfies a given condition. > > e.g. data{1},data{4},data{22},data{34}... etc all satisify a given condition. > > What I would like to be able to do is obtain an average of data{1}, data{4}, data{22}... etc but I would like to do it in such a way that I don't have to manually type in the address, instead I can simply have a formula that automatically retrives all the data{j} for all the elements j in the address array. > > Any ideas? > > Thanks, > > Ben c=0; for jj=1:length(adress) yourdata(jj,:)=data{adress(jj)}; end In this way you select the particular data one by one, and in the matrix your data you'll have a matrix full of only your usefule data.
From: Ben Williams on 2 Jun 2010 11:43 "Luca Zanotti Fragonara" <Luca_Zanotti(a)libero.it> wrote in message <hu5snc$l2f$1(a)fred.mathworks.com>... > "Ben Williams" <benjamin.williams(a)remove.this.plymouth.ac.uk> wrote in message <hu5s4k$ali$1(a)fred.mathworks.com>... > > Hello, > > > > I woudl like to know how to use the element values within an array as the index values of another array: > > > > For example: > > > > address = [1,4,22,34,35,36,37,48] > > > > Each of the the element values in the above array correspond to a cell address where the data satisfies a given condition. > > > > e.g. data{1},data{4},data{22},data{34}... etc all satisify a given condition. > > > > What I would like to be able to do is obtain an average of data{1}, data{4}, data{22}... etc but I would like to do it in such a way that I don't have to manually type in the address, instead I can simply have a formula that automatically retrives all the data{j} for all the elements j in the address array. > > > > Any ideas? > > > > Thanks, > > > > Ben > c=0; > for jj=1:length(adress) > yourdata(jj,:)=data{adress(jj)}; > end > > In this way you select the particular data one by one, and in the matrix your data you'll have a matrix full of only your usefule data. Thanks, much apprecieted. However all I get is the following error message: ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'cell'. Thanks, Ben
From: Luca Zanotti Fragonara on 3 Jun 2010 05:11 If you don't say us how is your cell vector, we cannot help you. Look at this code, this is working: empty=zeros(1,1000); data=cell(50,1); address = [1,4,22,34,35,36,37,48]; %To fill cell vector of numbers: for ii=1:50 data{ii}=empty; end %Select address cell data: c=0; for jj=1:length(address) yourdata(jj,:)=data{address(jj)}; end
|
Pages: 1 Prev: changing the sign of a vector Next: formula from curves for two inputs |