Resolution exercise Octave

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

Resolution exercise Octave

Simone
Hello
I am trying to solve an exercise on Octave and would like some help.
I have a matrix A (10x5) with numbers from 1 to 80 random.
From this matrix, 5 numbers are drawn, forming matrix B (1x5).
I need to generate another matrix (10x5), where the numbers in matrix B are
equal to A returns the value 1 and if different, returns the value 0. How
can I do this?
Thank you!



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


Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

Samuele Zampini
I think that a couple of "for" loops are enough.

Check each element and place there 0 or 1.


HTH,
Samuele



On Mon, Apr 20, 2020 at 10:18 AM Simone <[hidden email]> wrote:
Hello
I am trying to solve an exercise on Octave and would like some help.
I have a matrix A (10x5) with numbers from 1 to 80 random.
From this matrix, 5 numbers are drawn, forming matrix B (1x5).
I need to generate another matrix (10x5), where the numbers in matrix B are
equal to A returns the value 1 and if different, returns the value 0. How
can I do this?
Thank you!



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




Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

Doug Stewart-4
In reply to this post by Simone


On Mon, Apr 20, 2020 at 4:18 AM Simone <[hidden email]> wrote:
Hello
I am trying to solve an exercise on Octave and would like some help.
I have a matrix A (10x5) with numbers from 1 to 80 random.
From this matrix, 5 numbers are drawn, forming matrix B (1x5).
I need to generate another matrix (10x5), where the numbers in matrix B are
equal to A returns the value 1 and if different, returns the value 0. How
can I do this?
Thank you!



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



Try reading this page:



--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

nrjank
Administrator
In reply to this post by Simone
On Mon, Apr 20, 2020 at 4:18 AM Simone <[hidden email]> wrote:
Hello
I am trying to solve an exercise on Octave and would like some help.
I have a matrix A (10x5) with numbers from 1 to 80 random.
From this matrix, 5 numbers are drawn, forming matrix B (1x5).
I need to generate another matrix (10x5), where the numbers in matrix B are
equal to A returns the value 1 and if different, returns the value 0. How
can I do this?
Thank you!

look at the help for function 'ismember'.  I believe it will do exactly what you're looking for. 


Reply | Threaded
Open this post in threaded view
|

Re: Resolution exercise Octave

Francesco Potortì
In reply to this post by Simone
>I am trying to solve an exercise on Octave and would like some help.
>I have a matrix A (10x5) with numbers from 1 to 80 random.
>From this matrix, 5 numbers are drawn, forming matrix B (1x5).
>I need to generate another matrix (10x5), where the numbers in matrix B are
>equal to A returns the value 1 and if different, returns the value 0. How
>can I do this?

Do you need to just make it work?  If yes, this is good enough and does
not require much Octave competence:

Simone Zampini:
>I think that a couple of "for" loops are enough.
>
>Check each element and place there 0 or 1.

If you need to demonstrate a good grasp on the vector operators you
should vectorialise you code.  The basic step is to create a new 10x5
matrix to which matrix A should be compared.

--
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
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it