From: Richard on 10 Aug 2010 06:16 I have a cell array where a specific data set is stored on each row. The first element of each row is an integer. I want to find all instances of the max integer value and delete all rows that do not contain the value as their first element. for example: mycell={21, anObject, anArray; 21, anObject, anArray; 12, anObject, anArray; 8, anObject, anArray;} I want to delete all rows that don't start with the max value. In this case, 21. Whats the most efficient way to do this?
From: Tiago Sousa on 10 Aug 2010 07:18 On Aug 10, 11:16 am, "Richard " <REMOVETHISrcaldwel...(a)yahoo.com> wrote: > I have a cell array where a specific data set is stored on each row. The first element of each row is an integer. I want to find all instances of the max integer value and delete all rows that do not contain the value as their first element. for example: > mycell={21, anObject, anArray; > 21, anObject, anArray; > 12, anObject, anArray; > 8, anObject, anArray;} > I want to delete all rows that don't start with the max value. In this case, 21. > Whats the most efficient way to do this? Hi... The most efficient way that i found: example: mycell={21, anObject, anArray; 21, anObject, anArray; 12, anObject, anArray; 8, anObject, anArray;} First, convert a cell array to a single matrix using the command cell2mat, in this case: myMatrix=cell2mat(mycell(:,1)) -> convert only the numeric values in the 1º column Second, find the rows with values different from the max (in this case 21): id=find(a~=max(a)); mycell(id,:)=[]; -> delete the rows that not contain the maximum value (in this case are 3 and 4 rows). Regards, Tiago Sousa
From: us on 10 Aug 2010 08:27 "Richard " <REMOVETHISrcaldwellie(a)yahoo.com> wrote in message <i3r8t4$jgs$1(a)fred.mathworks.com>... > I have a cell array where a specific data set is stored on each row. The first element of each row is an integer. I want to find all instances of the max integer value and delete all rows that do not contain the value as their first element. for example: > mycell={21, anObject, anArray; > 21, anObject, anArray; > 12, anObject, anArray; > 8, anObject, anArray;} > I want to delete all rows that don't start with the max value. In this case, 21. > Whats the most efficient way to do this? one of the many solutions % the data % - a simplified version... c={ 1 10 100 2 20 200 1 10 300 2 20 400 1 10 500 }; % the engine c1=[c{:,1}]; ix=c1==max(c1); r=c(ix,:); % the result disp(r); %{ [2] [20] [200] [2] [20] [400] %} us
From: Richard on 10 Aug 2010 16:25 "us " <us(a)neurol.unizh.ch> wrote in message <i3rgip$j2b$1(a)fred.mathworks.com>... > "Richard " <REMOVETHISrcaldwellie(a)yahoo.com> wrote in message <i3r8t4$jgs$1(a)fred.mathworks.com>... > > I have a cell array where a specific data set is stored on each row. The first element of each row is an integer. I want to find all instances of the max integer value and delete all rows that do not contain the value as their first element. for example: > > mycell={21, anObject, anArray; > > 21, anObject, anArray; > > 12, anObject, anArray; > > 8, anObject, anArray;} > > I want to delete all rows that don't start with the max value. In this case, 21. > > Whats the most efficient way to do this? > > one of the many solutions > > % the data > % - a simplified version... > c={ > 1 10 100 > 2 20 200 > 1 10 300 > 2 20 400 > 1 10 500 > }; > % the engine > c1=[c{:,1}]; > ix=c1==max(c1); > r=c(ix,:); > % the result > disp(r); > %{ > [2] [20] [200] > [2] [20] [400] > %} > > us thanks guys. neat solution..
|
Pages: 1 Prev: Loading data from sepecifi multiple CSV files? (wildcard) Next: about RTW and windows |