Extraction of elements of an array inside the other array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Extraction of elements of an array inside the other array

GK19
period (t1, t2, t3) = time (p)
where t1 , t2, t3 are n dimensional arrays say  
t1 = (1,3,4,6,8,9,0,5,4,)
t2 = (3)
t3 = (4,56,7,8,5,1)
i want to show the 5th element of t1 as the output.
Output should be 8
how do i do that?



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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

nrjank
Administrator
On Sat, Apr 4, 2020 at 5:40 PM GK19 <[hidden email]> wrote:
period (t1, t2, t3) = time (p)
where t1 , t2, t3 are n dimensional arrays say 
t1 = (1,3,4,6,8,9,0,5,4,)
t2 = (3)
t3 = (4,56,7,8,5,1)
i want to show the 5th element of t1 as the output.
Output should be 8
how do i do that?

octave:1> t1 = [1,3,4,6,8,9,0,5,4];
octave:2> t1(5)
ans =  8

arrays are defined with [] not ()

and you should learn about array indexing:




Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

GK19
I will try to explain this way
Period (5,1,3) = 12
so the value of time is 12
Now i have trace back by taking the value of time ie 12, i need to get the
value of the 5th element of t1
is it possible?



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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

Francesco Potortì
Ganesh Rkini:
>I will try to explain this way
>Period (5,1,3) = 12
>so the value of time is 12

Is Period a multidim array or a function?

>Now i have trace back by taking the value of time ie 12, i need to get the
>value of the 5th element of t1

What is t1?

--
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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

GK19

Is Period a multidim array or a function? -- Yes it is a function

What is t1? --

period (t1, t2, t3) = time (p)
where t1 , t2, t3 are n dimensional arrays say  
t1 = (1,3,4,6,8,9,0,5,4,)
t2 = (3)
t3 = (4,56,7,8,5,1)

t1 is a n dimensional array



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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

nrjank
Administrator


On Sun, Apr 5, 2020, 8:40 AM GK19 <[hidden email]> wrote:

Is Period a multidim array or a function? -- Yes it is a function

What is t1? --

period (t1, t2, t3) = time (p)
where t1 , t2, t3 are n dimensional arrays say 
t1 = (1,3,4,6,8,9,0,5,4,)
t2 = (3)
t3 = (4,56,7,8,5,1)

t1 is a n dimensional array


I think we need more information about what you're trying to do. Can you share a minimal code example?


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

GK19
period (t1, t2, t3) = time (p)
where t1 , t2, t3 are n dimensional arrays say  
a = (1,3,4,6,8,9,0,5,4,)
b = (3)
c = (4,56,7,8,5,1)

t1 = length(a)
t2 = length(b)
t1 = length(c)

Since I have a function called period it gives some random value based on
the parameters that have been passed to t1, t2, t3.

output -- period (5,1,2) = 12.


what I'm trying is to do trace it back
i have time as 12, just by looking at the output i want to trace the value
of t1 that has been passed.

so my output so look like 8, which is the 5th element of a.

how can i do that ? kindly help




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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

GK19
This post was updated on .
In reply to this post by nrjank
a = (1,3,4,6,8,9,0,5,4,)
b = (3)
c = (4,56,7,8,5,1)
a, b,c are saved in .vec extension
for t1 =1:1:length(a)
        for t2=1:1:length(b)
        for  t3=1:1:length(c)
                period_fun(a,b,c)=time(p);
                p=p+1;
        end
        end
        end
So this code will give me the time
 period fun(5,1,3) which means it will fetch
5th element of a = 8, 1st element of b = 3, 3rd element of c = 7, and the
output is time = 1.1
Now just by looking the output time 1.1 i want to extract the 5th element of
a or the 1st element of b or  3rd element of c and get that element as
output
is it possible ?



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


Reply | Threaded
Open this post in threaded view
|

Re: Extraction of elements of an array inside the other array

Thomas D. Dean-2
On 2020-04-05 09:21, GK19 wrote:

> a = (1,3,4,6,8,9,0,5,4,)
> b = (3)
> c = (4,56,7,8,5,1)
> a, b,c are saved in .vec extension
> for t1 =1:1:length(a)
>          for t2=1:1:length(b)
>          for  t3=1:1:length(c)
>                  period_fun(a,b,c)=time(p);
>                  p=p+1;
>          end
>          end
>          end
> So this code will give me the time
>   period fun(5,1,3) which means it will fetch
> 5th element of a = 8, 1st element of b = 1, 3rd element of c = 7, and the
> output is time = 1.1
> Now just by looking the output time 1.1 i want to extract the 5th element of
> a or the 1st element of b or  3rd element of c and get that element as
> output
> is it possible ?
>
>
>
> --
> Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
>
>

To assign a list to a, use [].  Same for b and c.

Look at help list.

Tom Dean