I have a matrix of size 10000x5 with format [id, year, month, day, value]
For example:
[ 1 2004 1 1 100;
1 2004 1 2 201;
2 2004 1 1 30;
2 2004 1 2 123;
2 2005 1 1 300;
2 2005 1 2 103;
...]
I would like to filter and copy a subset of this matrix into another matrix, given the search criteria year==2004 && month==1 && day==1. So what I thought is to first find out what is the row index of vectors which match to the given criteria.
First I tried with,
[row] = find((data(:,2) == 2004 && data(:,3) == 1 && data(:,4) == 1));
But it doesn't seems to work with multiple criteria, I get the error
Operands to the || and && operators must be convertible to logical scalar values.
Next I tried with
key = [2004 1 1];
[~,index] = ismember(data,key,'rows')
But it said
Error using ismember. A and S must have the same number of columns.
Is there any way to refine the syntax, or another API to search with multiple criteria?
See the proposed answer here. It proposes an alternative approach. In your case, you would have :
key = [NaN 2004 1 1 NaN];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With