Csound Csound-dev Csound-tekno Search About

[Csnd] how to detect the index

Date2021-03-01 12:38
FromStefan Thomas
Subject[Csnd] how to detect the index
Dear community,
I would like to know, how I could detect the index of a special element in an array.
If this would be the array:
giTubMidNotnums[ ] fillarray 45, 52.28, 53.13, 56.6, 60.4, 67.68, 68.53, 72.0, 75.9, 83.18, 84.03, 87.5
how could I find the index for e.g. 60.4
Thanks for any hint!
Stefan
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-03-01 13:17
FromEduardo Moguillansky
SubjectRe: [Csnd] how to detect the index

Look at bisect here:

https://csound-plugins.github.io/csound-plugins/opcodes/bisect.html

On 01.03.21 13:38, Stefan Thomas wrote:
Dear community,
I would like to know, how I could detect the index of a special element in an array.
If this would be the array:
giTubMidNotnums[ ] fillarray 45, 52.28, 53.13, 56.6, 60.4, 67.68, 68.53, 72.0, 75.9, 83.18, 84.03, 87.5
how could I find the index for e.g. 60.4
Thanks for any hint!
Stefan
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2021-03-01 15:26
Fromjoachim heintz
SubjectRe: [Csnd] how to detect the index
or you write a small udo which runs through the array and returns the 
index in case the element is being found:

opcode SearchEl, i, ii[]
  ;returns -1 if iEl is not in iArr, otherwise the index
  iEl, iArr[] xin
  iRes = -1
  indx = 0
  while indx < lenarray:i(iArr) do
   if iEl == iArr[indx] then
    iRes = indx
    igoto end
   endif
   indx += 1
  od
  end:
  xout iRes
endop

instr 1
  iArr[] fillarray 1,2,3,4,5
  iIndex SearchEl 3, iArr
  print iIndex
endin

	j

On 01/03/2021 14:17, Eduardo Moguillansky wrote:
> Look at bisect here:
> 
> https://csound-plugins.github.io/csound-plugins/opcodes/bisect.html
> 
> On 01.03.21 13:38, Stefan Thomas wrote:
>> Dear community,
>> I would like to know, how I could detect the index of a special 
>> element in an array.
>> If this would be the array:
>> giTubMidNotnums[ ] fillarray 45, 52.28, 53.13, 56.6, 60.4, 67.68, 
>> 68.53, 72.0, 75.9, 83.18, 84.03, 87.5
>> how could I find the index for e.g. 60.4
>> Thanks for any hint!
>> Stefan
>> Csound mailing list Csound@listserv.heanet.ie 
>>  
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
>> https://github.com/csound/csound/issues Discussions of bugs and 
>> features can be posted here 
> Csound mailing list Csound@listserv.heanet.ie 
>  
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to 
> https://github.com/csound/csound/issues Discussions of bugs and features 
> can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2021-03-06 21:21
FromStefan Thomas
SubjectRe: [Csnd] how to detect the index
Thanks for Your help!
I think I will use the udo.
Stefan

Am Mo., 1. März 2021 um 16:26 Uhr schrieb joachim heintz <jh@joachimheintz.de>:
or you write a small udo which runs through the array and returns the
index in case the element is being found:

opcode SearchEl, i, ii[]
  ;returns -1 if iEl is not in iArr, otherwise the index
  iEl, iArr[] xin
  iRes = -1
  indx = 0
  while indx < lenarray:i(iArr) do
   if iEl == iArr[indx] then
    iRes = indx
    igoto end
   endif
   indx += 1
  od
  end:
  xout iRes
endop

instr 1
  iArr[] fillarray 1,2,3,4,5
  iIndex SearchEl 3, iArr
  print iIndex
endin

        j

On 01/03/2021 14:17, Eduardo Moguillansky wrote:
> Look at bisect here:
>
> https://csound-plugins.github.io/csound-plugins/opcodes/bisect.html
>
> On 01.03.21 13:38, Stefan Thomas wrote:
>> Dear community,
>> I would like to know, how I could detect the index of a special
>> element in an array.
>> If this would be the array:
>> giTubMidNotnums[ ] fillarray 45, 52.28, 53.13, 56.6, 60.4, 67.68,
>> 68.53, 72.0, 75.9, 83.18, 84.03, 87.5
>> how could I find the index for e.g. 60.4
>> Thanks for any hint!
>> Stefan
>> Csound mailing list Csound@listserv.heanet.ie
>> <mailto:Csound@listserv.heanet.ie>
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and
>> features can be posted here
> Csound mailing list Csound@listserv.heanet.ie
> <mailto:Csound@listserv.heanet.ie>
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features
> can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here