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:
Unique function

Subject: Unique function

From: Lin

Date: 6 Feb, 2009 13:29:01

Message: 1 of 6

For example:

a = [content1] [content 2] [ ]
      [ ] [content 3] [content 4 ]

content is actually a matrix --> [1;1]

I want to pass the content from column 2 to Equ.

Equ = x*[content2] + y*[content3]

As there are only 2 variables(x and y), only column 2 meets the requirement. My idea is to let z = unique(a,'columns'), after which pass the content from column 2 to the equation, but there is an error. Please advise. Thanks.

Subject: Unique function

From: Lin

Date: 7 Feb, 2009 03:15:04

Message: 2 of 6

Hello,
I can actually pass the content to the Equ by using [x*a{1,2} + y*a{2,2}]. Whenever I change the data, I need to change the content address manually. Any ideas if there is a simpler way? (once i change the data, content address will be taken care by the program based on the description that i ve wriiten earlier) Thanks.

"Lin " <shenqlv@yahoo.com> wrote in message <gmhdut$181$1@fred.mathworks.com>...
> For example:
>
> a = [content1] [content 2] [ ]
> [ ] [content 3] [content 4 ]
>
> content is actually a matrix --> [1;1]
>
> I want to pass the content from column 2 to Equ.
>
> Equ = x*[content2] + y*[content3]
>
> As there are only 2 variables(x and y), only column 2 meets the requirement. My idea is to let z = unique(a,'columns'), after which pass the content from column 2 to the equation, but there is an error. Please advise. Thanks.

Subject: Unique function

From: ImageAnalyst

Date: 7 Feb, 2009 05:36:20

Message: 3 of 6

On Feb 6, 10:15=A0pm, "Lin " <shen...@yahoo.com> wrote:
> Hello,
> I can actually pass the content to the Equ by using [x*a{1,2} + y*a{2,2}]=
. Whenever I change the data, I need to change the content address manually=
. Any ideas if there is a simpler way? (once i change the data, content add=
ress will be taken care by the program based on the description that i ve w=
riiten earlier) Thanks.
>
>
>
> "Lin " <shen...@yahoo.com> wrote in message <gmhdut$18...@fred.mathworks.=
com>...
> > For example:
>
> > a =3D [content1] [content 2] [ ]
> > =A0 =A0 =A0 [ ] =A0 =A0 =A0 =A0 =A0 =A0 [content 3] [content 4 ]
>
> > content is actually a matrix --> [1;1]
>
> > I want to pass the content from column 2 to Equ.
>
> > Equ =3D x*[content2] + y*[content3]
>
> > As there are only 2 variables(x and y), only column 2 meets the require=
ment. My idea is to let z =3D unique(a,'columns'), after which pass the con=
tent from column 2 to the equation, but there is an error. Please advise. T=
hanks.- Hide quoted text -
>
> - Show quoted text -

-----------------------------------
I'm not really sure what you're trying to do, but perhaps the isempty
() function will help you. You can use it to find out if a matrix
element is empty or has "content" in it.

Subject: Unique function

From: Lin

Date: 7 Feb, 2009 07:18:01

Message: 4 of 6

I try to break down my question into smaller segments.

eg = [1;1] [2;2] [3;3]
        [] [4;4] []

Equ = x*[] + y*[]

% program
find(which column has 2 items)
pass the content of those 2 items to Equ
%expected result:
Equ = x*[2;2] + y* [4;4]

i am not sure if i should use the unique function for the program portion. that explain my subject title.
I hope this is much clearer. sorry for the poor description.

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <647493c8-db01-4b20-be78-f305d5eb6e77@v15g2000yqn.googlegroups.com>...
> On Feb 6, 10:15=A0pm, "Lin " <shen...@yahoo.com> wrote:
> > Hello,
> > I can actually pass the content to the Equ by using [x*a{1,2} + y*a{2,2}]=
> . Whenever I change the data, I need to change the content address manually=
> . Any ideas if there is a simpler way? (once i change the data, content add=
> ress will be taken care by the program based on the description that i ve w=
> riiten earlier) Thanks.
> >
> >
> >
> > "Lin " <shen...@yahoo.com> wrote in message <gmhdut$18...@fred.mathworks.=
> com>...
> > > For example:
> >
> > > a =3D [content1] [content 2] [ ]
> > > =A0 =A0 =A0 [ ] =A0 =A0 =A0 =A0 =A0 =A0 [content 3] [content 4 ]
> >
> > > content is actually a matrix --> [1;1]
> >
> > > I want to pass the content from column 2 to Equ.
> >
> > > Equ =3D x*[content2] + y*[content3]
> >
> > > As there are only 2 variables(x and y), only column 2 meets the require=
> ment. My idea is to let z =3D unique(a,'columns'), after which pass the con=
> tent from column 2 to the equation, but there is an error. Please advise. T=
> hanks.- Hide quoted text -
> >
> > - Show quoted text -
>
> -----------------------------------
> I'm not really sure what you're trying to do, but perhaps the isempty
> () function will help you. You can use it to find out if a matrix
> element is empty or has "content" in it.

Subject: Unique function

From: Matt Fig

Date: 7 Feb, 2009 07:34:01

Message: 5 of 6

a = {[1;1] [2;1] [3;2]
        [] [4;6] [] }
idx = find(sum(~cellfun(@isempty,a))==2)
Equ = 5*a{1,idx} + 2*a{2,idx}





8gne_a_fwlmm}_r,`ltjiK}_}mm%rk_cm%C`_c}}cnfgrss}kj_faW>}}mc

Subject: Unique function

From: Lin

Date: 7 Feb, 2009 10:18:01

Message: 6 of 6

Thanks Matt.

Hello.
With that I am able to piece all the programs i am working into a single program as shown. i am actually storing the equivalent row and column subscripts when the items in a column equals to 2. When performing for-loop, i will use the content found from I(1),J(2) and I(2),J(2) and substitute into Equ.
How should i edit the program so that i will also use the content found from I(1),J(3) and I(3),J(3) ? Thanks. Please help me in this.

expected result:
for-loop
%use the result from I(1),J(2) and I(2),J(2)
cArray{in} = row1(i)*a{I(1),J(2)} + row2(i)*a{I(2),J(2)};
 in = in+1;
end;

%use the result from I(1),J(3) and I(3),J(3) and go through for-loop again.
%this time, page 2 of cArray will be used to store the Equ result.

%Program
a = {[1;1] [1;0] [3;2]
        [] [0;1] [4;5] }
idx =sum(~cellfun(@isempty,a))<=1;
a(:,idx)={[]};
[I,J]=ind2sub(size(a),find(~cellfun(@isempty,a)));
disp([I J])
idx2 = unique(J);
ix = dec2bin(0:3)'-'0' ;
 row1 = ix(1,:);
 row2 = ix(2,:);
  in= 1;
  for i = 1:4
     cArray{in} = row1(i)*a{I(1),J(2)} + row2(i)*a{I(2),J(2)};
     in = in+1;
 end;


"Matt Fig" <spamanon@yahoo.com> wrote in message <gmjdh9$i8k$1@fred.mathworks.com>...
> a = {[1;1] [2;1] [3;2]
> [] [4;6] [] }
> idx = find(sum(~cellfun(@isempty,a))==2)
> Equ = 5*a{1,idx} + 2*a{2,idx}

Tags for this Thread

No tags are associated with 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