Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Binary input of a 3D Lookup Table

Subject: Binary input of a 3D Lookup Table

From: Andrea

Date: 31 Jul, 2013 09:45:13

Message: 1 of 9

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?

Subject: Binary input of a 3D Lookup Table

From: dpb

Date: 31 Jul, 2013 15:54:54

Message: 2 of 9

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

--

Subject: Binary input of a 3D Lookup Table

From: Andrea

Date: 31 Jul, 2013 18:10:13

Message: 3 of 9

dpb <none@non.net> wrote in message <ktbc0h$pom$1@speranza.aioe.org>...
> 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
>
> --

Thank you.
And in simulink? How i set it?

Subject: Binary input of a 3D Lookup Table

From: dpb

Date: 31 Jul, 2013 21:14:26

Message: 4 of 9

On 7/31/2013 1:10 PM, Andrea wrote:
...


> And in simulink? How i set it?

I've no klew...I've never even seen a Simulink installation what more
used it.

I presume it would have to be an s-file?

--

Subject: Binary input of a 3D Lookup Table

From: dpb

Date: 31 Jul, 2013 21:28:41

Message: 5 of 9

On 7/31/2013 4:14 PM, dpb wrote:
> On 7/31/2013 1:10 PM, Andrea wrote:
> ...
>
>
>> And in simulink? How i set it?
>
> I've no klew...I've never even seen a Simulink installation what more
> used it.
>
> I presume it would have to be an s-file?
>
OBTW, an erratum on the function--you'll have to set the output for all
paths or will error...

function v=lookitup(x,y,vec)
% return value of y matching vector vec in table x if found
% empty result if not found

   v=[];
   [~,ia]=intersect(x,vec,'rows');
   if ~isempty(ia), v=y(ia); end

Subject: Binary input of a 3D Lookup Table

From: Andrea

Date: 1 Aug, 2013 06:40:14

Message: 6 of 9

dpb <none@non.net> wrote in message <ktbvih$h2m$2@speranza.aioe.org>...
> On 7/31/2013 4:14 PM, dpb wrote:
> > On 7/31/2013 1:10 PM, Andrea wrote:
> > ...
> >
> >
> >> And in simulink? How i set it?
> >
> > I've no klew...I've never even seen a Simulink installation what more
> > used it.
> >
> > I presume it would have to be an s-file?
> >
> OBTW, an erratum on the function--you'll have to set the output for all
> paths or will error...
>
> function v=lookitup(x,y,vec)
> % return value of y matching vector vec in table x if found
> % empty result if not found
>
> v=[];
> [~,ia]=intersect(x,vec,'rows');
> if ~isempty(ia), v=y(ia); end


But there is already the simulink block called "Direct Lookup Table (3D)", I wanted to use it but I don't know how to set it

Subject: Binary input of a 3D Lookup Table

From: dpb

Date: 1 Aug, 2013 12:59:31

Message: 7 of 9

On 8/1/2013 1:40 AM, Andrea wrote:
> dpb <none@non.net> wrote in message <ktbvih$h2m$2@speranza.aioe.org>...
>> On 7/31/2013 4:14 PM, dpb wrote:
>> > On 7/31/2013 1:10 PM, Andrea wrote:
>> > ...
>> >
>> >
>> >> And in simulink? How i set it?
>> >
>> > I've no klew...I've never even seen a Simulink installation what more
>> > used it.
>> >
>> > I presume it would have to be an s-file?
>> >
>> OBTW, an erratum on the function--you'll have to set the output for
>> all paths or will error...
>>
>> function v=lookitup(x,y,vec)
>> % return value of y matching vector vec in table x if found
>> % empty result if not found
>>
>> v=[];
>> [~,ia]=intersect(x,vec,'rows');
>> if ~isempty(ia), v=y(ia); end
>
>
> But there is already the simulink block called "Direct Lookup Table
> (3D)", I wanted to use it but I don't know how to set it

Surely you can read the documentation as readily as I, then...

Subject: Binary input of a 3D Lookup Table

From: Andrea

Date: 1 Aug, 2013 15:08:08

Message: 8 of 9

dpb <none@non.net> wrote in message <ktdm40$i11$1@speranza.aioe.org>...
> On 8/1/2013 1:40 AM, Andrea wrote:
> > dpb <none@non.net> wrote in message <ktbvih$h2m$2@speranza.aioe.org>...
> >> On 7/31/2013 4:14 PM, dpb wrote:
> >> > On 7/31/2013 1:10 PM, Andrea wrote:
> >> > ...
> >> >
> >> >
> >> >> And in simulink? How i set it?
> >> >
> >> > I've no klew...I've never even seen a Simulink installation what more
> >> > used it.
> >> >
> >> > I presume it would have to be an s-file?
> >> >
> >> OBTW, an erratum on the function--you'll have to set the output for
> >> all paths or will error...
> >>
> >> function v=lookitup(x,y,vec)
> >> % return value of y matching vector vec in table x if found
> >> % empty result if not found
> >>
> >> v=[];
> >> [~,ia]=intersect(x,vec,'rows');
> >> if ~isempty(ia), v=y(ia); end
> >
> >
> > But there is already the simulink block called "Direct Lookup Table
> > (3D)", I wanted to use it but I don't know how to set it
>
> Surely you can read the documentation as readily as I, then...

Thank you for your very useless answer!
The documentation doesn't help in my problem.

I solved doing simply this:

data=[5 3; 6 2]
data(:,:,2)=[4 4; 1 1]

and then setting DATA as parameter in the simulink block.

Subject: Binary input of a 3D Lookup Table

From: dpb

Date: 1 Aug, 2013 16:51:41

Message: 9 of 9

On 8/1/2013 10:08 AM, Andrea wrote:
...

> Thank you for your very useless answer!
> The documentation doesn't help in my problem.
...
Well, I told you I don't have any experience w/ Simulink--what do you
want from me in that case???

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us