select equal element between matrices

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

select equal element between matrices

gigiolone123
hi guys, a give you a difficult question

a=[3 2 5 5 6 6 2 3]
b=[0 1 0 0 1 1 0 0]
c=["a","b","a","a","b","c","a","a"]


I want combine each index with the others

ans:
3 0 a
2 1 b
5 0 a
5 0 a
6 1 b
6 1 c
2 0 a
3 0 b


I consider only the same pairs (3 0 a   and 5 0 a)


returns the number index of equal pairs
ans:[1 4]

it's possibile to do this avoit loop? thank






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: select equal element between matrices

Francesco Potortì
>a=[3 2 5 5 6 6 2 3]
>b=[0 1 0 0 1 1 0 0]
>c=["a","b","a","a","b","c","a","a"]
>
>I want combine each index with the others
>
>ans:
>3 0 a
>2 1 b
>5 0 a
>5 0 a
>6 1 b
>6 1 c
>2 0 a
>3 0 b
>
>I consider only the same pairs (3 0 a   and 5 0 a)
>
>returns the number index of equal pairs
>ans:[1 4]
>
>it's possibile to do this avoit loop? thank

I see that you have not received any answer.  I think this is because
your question is not clear.  At least, I have not understood it.

Can you try to clarify what is your purpose?

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



Reply | Threaded
Open this post in threaded view
|

Re: select equal element between matrices

Thomas D. Dean-2
On 2/10/19 1:38 PM, Francesco Potortì wrote:

>> a=[3 2 5 5 6 6 2 3]
>> b=[0 1 0 0 1 1 0 0]
>> c=["a","b","a","a","b","c","a","a"]
>>
>> I want combine each index with the others
>>
>> ans:
>> 3 0 a
>> 2 1 b
>> 5 0 a
>> 5 0 a
>> 6 1 b
>> 6 1 c
>> 2 0 a
>> 3 0 b
>>
>> I consider only the same pairs (3 0 a   and 5 0 a)
>>
>> returns the number index of equal pairs
>> ans:[1 4]
>>
>> it's possibile to do this avoit loop? thank
>
> I see that you have not received any answer.  I think this is because
> your question is not clear.  At least, I have not understood it.
>
> Can you try to clarify what is your purpose?
>


This looks like homework.  Look at num2str and consider a'

Tom Dean


Reply | Threaded
Open this post in threaded view
|

Re: select equal element between matrices

gigiolone123
In reply to this post by Francesco Potortì
Hi francesco

thank you for answer

i've this vector:

a=[3 2 5 5 6 6 2 3]
b=[0 1 0 0 1 1 0 0]
c=["a","b","a","a","b","c","a","a"]

i want to concatening element of string:

column 1: a(3)+b(0)+c("a") = 30a
column 2: a(2)+b(1)+c("b") = 21b
column 3: a(5)+b(0)+c("a") = 50b







--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: select equal element between matrices

Francesco Potortì
>i've this vector:
>
>a=[3 2 5 5 6 6 2 3]
>b=[0 1 0 0 1 1 0 0]
>c=["a","b","a","a","b","c","a","a"]
>
>i want to concatening element of string:
>
>column 1: a(3)+b(0)+c("a") = 30a
>column 2: a(2)+b(1)+c("b") = 21b
>column 3: a(5)+b(0)+c("a") = 50b

As Thomas Dean has pointed out, have a look at num2str, consider that
you want column vectors (a' is a column vector), and that you should
better understand hw indices work: a(3) is 5!

In short, you want to concatenate strings, and you should convert
numbers to strings to do that.

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it



Reply | Threaded
Open this post in threaded view
|

Re: select equal element between matrices

gigiolone123
thank you francesco..


ciao




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html