|
On 7/31/2013 4:45 AM, Andrea wrote:
> I have 3 binary input (0 or 1), and i want to have a lookup table like
> this:
>
> a b c | output
> 0 0 0 | 5
> 0 0 1 | 2
> 0 1 0 | 5
> 0 1 1 | 9
> etc..
>
> But i don't undersatnd how to set the 3D lookup table. How can i do?
Presuming it is all a 1:1 lookup, I'd do sotoo...
>> [I V]
ans =
0 0 0 5
0 0 1 2
0 1 0 5
0 1 1 9
>> [~,ia]=intersect(I,[0 0 1],'rows');
>> V(ia)
ans =
2
>> [~,ia]=intersect(I,[1 0 1],'rows')
ia =
Empty matrix: 0-by-1
>> if ~isempty(ia), VI=V(ia); end
>>
Wrap in a function...
function v=lookitup(x,y,vec)
% return value of y matching vector vec in table x if found
% empty result if not found
[~,ia]=intersect(x,vec,'rows');
if ~isempty(ia), v=y(ia); end
--
|