|
On 7/19/2012 6:11 AM, Matthew Hyett wrote:
> To the MATLAB community,
>
> I'm a novice to the MATLAB language and its many functions and so on,
> and have had difficulty finding much relevant information on matrix
> indexing with 'dependencies'.
>
> I was wondering if anyone knew of a function call(s) that would
> effectively solve the following.
>
> I have a matrix of values A (for example, 3 columns by 6 rows):
>
> A =
>
> 1 1 3
> 1 0 4
> 1 1 1
> 1 1 2
> 2 0 1
> 2 1 4
>
> I need to print to B a list (of counts or of values) of the third column
> dependent on the first or the second column, or both. For example, could
> I get printed, for values of 1 in column 1, the values of the third
> column dependent on, say, zero in the second?
>
> So B looks like:
>
> 3 1 2 4
...
Well, I don't see how B follows from your description at all--the only
value where A(:,1)==1 & A(:,2)==0 --> A(:,3)==4
For your result vector A(:,[1:2]) looks like
A =
1 1
1 0
1 1
2 1
>>
The problem as described --
>> A=[1 1 3;1 0 4; 1 1 1; 1 1 2;2 0 1;2 1 4];
>> B=A(ismember(A(:,[1:2]),[1 0],'rows'),3)
B =
4
>> inSet = sum(ismember(A(:,[1:2]),[1 0],'rows'))
ans =
1
>>
Salt conditions to suit...
Look at the doc for
doc ismember % and friends for such comparisons/selection processes
--
|