Finding the index of a specific element in a listIncrementing a nested list elementData Table Manipulation in...

Crack the bank account's password!

How do I purchase a drop bar bike that will be converted to flat bar?

Have any astronauts or cosmonauts died in space?

Why can all solutions to the simple harmonic motion equation be written in terms of sines and cosines?

Third wheel character

Coworker asking me to not bring cakes due to self control issue. What should I do?

Calculating list of areas between the curves in an intersection region

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

Converting numbers to words - Python

Boss asked me to sign a resignation paper without a date on it along with my new contract

Finding the index of a specific element in a list

Unable to repartition non-mounted SD card

Missing space after parenthesis in inline text

Does Plato's "Ring of Gyges" have a corrupting influence on its wearer?

Is the UK legally prevented from having another referendum on Brexit?

Why does my printer create notches on the Y surface?

Is there a way to pause a running process on Linux systems and resume later?

Expression for "unconsciously using words (or accents) used by a person you often talk with or listen to"?

How bad is a Computer Science course that doesn't teach Design Patterns?

Linearity Assumption

Why does a single AND gate need 60 transistors?

Can you help me solve this algebra problem?

Is the Maximum Use License for Everybody (MULE) a FOSS license?

What is formjacking?



Finding the index of a specific element in a list


Incrementing a nested list elementData Table Manipulation in MathematicaHow to set up and minimize a large system of equations to resolve the individual componentsGet positions of all non zero matrix elementsElements of a List according position in axisHow to display the indices/element positions of a ragged array?How to multiply specific columns in a matrix of data?Using Select function to select elements based on last element of nested listInserting columns into a large table of data and converting it into a {x,y,z} listCreating 3x3 Matrix using Table Function and then accessing an element













3












$begingroup$


I have searched everywhere to find an answer for this and have come up with nothing!



I have a data file containing two columns, one with wavelengths in nanometer (some with decimal digits, others just with a decimal point) and the other with spectral irradiance values.



I am trying to make a new table that takes as the first column all the wavelengths and in the second column I divide the spectral values by photon energy to get photon flux. However, in this new table I want to stop at a certain index i where the wavelength corresponds to a specific photon energy that I calculated. This is the code I use. It works.



Here is a small portion of the data table:



{280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5, 

SSpecUsed = Drop[Table[{SSpecWavelength[[i]],SSpecIntensity[[i]]/Eph[SSpecWavelength[[i]]]*Subscript[En, G, Si]*q /. numval}, {i, 0, 949, 1}], 1];


My issue is that I manually found the index (949) at which the wavelength is 1107. nm. In a later exercise I need to integrate over this data up to different indices (so for example integrating all the way up to wavelength 2000 and in the next step only up to 1999). So I tried replacing the 949 value by:



Position[SSpecWavelength, Subscript[[Lambda], G][Eg_]]/.numval


So basically I try using Position to find the index at which the element in the list is equal to the wavelenght that I calculate based on an energy value. When I run it I get empty curly brackets. I even tried this:



Position[SSpecWavelength, 1107.]


and I still get empty curly brackets. I checked and I know for a fact that the element at index 949 is equal to 1107. so why does it not return me the index?



Is there another (better/simpler) way to accomplish what I want?



Thanks in advance, hope the problem is clear!










share|improve this question











$endgroup$












  • $begingroup$
    Would you please provide a small portion of the data table as an example? That would make live much easier for us.
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
    $endgroup$
    – Henrik Schumacher
    2 hours ago










  • $begingroup$
    FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
    $endgroup$
    – alonoid
    2 hours ago










  • $begingroup$
    How do I only use the returned index number without the curly brackets? How do I remove the brackets?
    $endgroup$
    – alonoid
    2 hours ago
















3












$begingroup$


I have searched everywhere to find an answer for this and have come up with nothing!



I have a data file containing two columns, one with wavelengths in nanometer (some with decimal digits, others just with a decimal point) and the other with spectral irradiance values.



I am trying to make a new table that takes as the first column all the wavelengths and in the second column I divide the spectral values by photon energy to get photon flux. However, in this new table I want to stop at a certain index i where the wavelength corresponds to a specific photon energy that I calculated. This is the code I use. It works.



Here is a small portion of the data table:



{280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5, 

SSpecUsed = Drop[Table[{SSpecWavelength[[i]],SSpecIntensity[[i]]/Eph[SSpecWavelength[[i]]]*Subscript[En, G, Si]*q /. numval}, {i, 0, 949, 1}], 1];


My issue is that I manually found the index (949) at which the wavelength is 1107. nm. In a later exercise I need to integrate over this data up to different indices (so for example integrating all the way up to wavelength 2000 and in the next step only up to 1999). So I tried replacing the 949 value by:



Position[SSpecWavelength, Subscript[[Lambda], G][Eg_]]/.numval


So basically I try using Position to find the index at which the element in the list is equal to the wavelenght that I calculate based on an energy value. When I run it I get empty curly brackets. I even tried this:



Position[SSpecWavelength, 1107.]


and I still get empty curly brackets. I checked and I know for a fact that the element at index 949 is equal to 1107. so why does it not return me the index?



Is there another (better/simpler) way to accomplish what I want?



Thanks in advance, hope the problem is clear!










share|improve this question











$endgroup$












  • $begingroup$
    Would you please provide a small portion of the data table as an example? That would make live much easier for us.
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
    $endgroup$
    – Henrik Schumacher
    2 hours ago










  • $begingroup$
    FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
    $endgroup$
    – alonoid
    2 hours ago










  • $begingroup$
    How do I only use the returned index number without the curly brackets? How do I remove the brackets?
    $endgroup$
    – alonoid
    2 hours ago














3












3








3





$begingroup$


I have searched everywhere to find an answer for this and have come up with nothing!



I have a data file containing two columns, one with wavelengths in nanometer (some with decimal digits, others just with a decimal point) and the other with spectral irradiance values.



I am trying to make a new table that takes as the first column all the wavelengths and in the second column I divide the spectral values by photon energy to get photon flux. However, in this new table I want to stop at a certain index i where the wavelength corresponds to a specific photon energy that I calculated. This is the code I use. It works.



Here is a small portion of the data table:



{280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5, 

SSpecUsed = Drop[Table[{SSpecWavelength[[i]],SSpecIntensity[[i]]/Eph[SSpecWavelength[[i]]]*Subscript[En, G, Si]*q /. numval}, {i, 0, 949, 1}], 1];


My issue is that I manually found the index (949) at which the wavelength is 1107. nm. In a later exercise I need to integrate over this data up to different indices (so for example integrating all the way up to wavelength 2000 and in the next step only up to 1999). So I tried replacing the 949 value by:



Position[SSpecWavelength, Subscript[[Lambda], G][Eg_]]/.numval


So basically I try using Position to find the index at which the element in the list is equal to the wavelenght that I calculate based on an energy value. When I run it I get empty curly brackets. I even tried this:



Position[SSpecWavelength, 1107.]


and I still get empty curly brackets. I checked and I know for a fact that the element at index 949 is equal to 1107. so why does it not return me the index?



Is there another (better/simpler) way to accomplish what I want?



Thanks in advance, hope the problem is clear!










share|improve this question











$endgroup$




I have searched everywhere to find an answer for this and have come up with nothing!



I have a data file containing two columns, one with wavelengths in nanometer (some with decimal digits, others just with a decimal point) and the other with spectral irradiance values.



I am trying to make a new table that takes as the first column all the wavelengths and in the second column I divide the spectral values by photon energy to get photon flux. However, in this new table I want to stop at a certain index i where the wavelength corresponds to a specific photon energy that I calculated. This is the code I use. It works.



Here is a small portion of the data table:



{280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5, 

SSpecUsed = Drop[Table[{SSpecWavelength[[i]],SSpecIntensity[[i]]/Eph[SSpecWavelength[[i]]]*Subscript[En, G, Si]*q /. numval}, {i, 0, 949, 1}], 1];


My issue is that I manually found the index (949) at which the wavelength is 1107. nm. In a later exercise I need to integrate over this data up to different indices (so for example integrating all the way up to wavelength 2000 and in the next step only up to 1999). So I tried replacing the 949 value by:



Position[SSpecWavelength, Subscript[[Lambda], G][Eg_]]/.numval


So basically I try using Position to find the index at which the element in the list is equal to the wavelenght that I calculate based on an energy value. When I run it I get empty curly brackets. I even tried this:



Position[SSpecWavelength, 1107.]


and I still get empty curly brackets. I checked and I know for a fact that the element at index 949 is equal to 1107. so why does it not return me the index?



Is there another (better/simpler) way to accomplish what I want?



Thanks in advance, hope the problem is clear!







list-manipulation numerical-value






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









m_goldberg

86.7k872196




86.7k872196










asked 2 hours ago









alonoidalonoid

212




212












  • $begingroup$
    Would you please provide a small portion of the data table as an example? That would make live much easier for us.
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
    $endgroup$
    – Henrik Schumacher
    2 hours ago










  • $begingroup$
    FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
    $endgroup$
    – alonoid
    2 hours ago










  • $begingroup$
    How do I only use the returned index number without the curly brackets? How do I remove the brackets?
    $endgroup$
    – alonoid
    2 hours ago


















  • $begingroup$
    Would you please provide a small portion of the data table as an example? That would make live much easier for us.
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
    $endgroup$
    – Henrik Schumacher
    2 hours ago






  • 1




    $begingroup$
    In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
    $endgroup$
    – Henrik Schumacher
    2 hours ago










  • $begingroup$
    FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
    $endgroup$
    – alonoid
    2 hours ago










  • $begingroup$
    How do I only use the returned index number without the curly brackets? How do I remove the brackets?
    $endgroup$
    – alonoid
    2 hours ago
















$begingroup$
Would you please provide a small portion of the data table as an example? That would make live much easier for us.
$endgroup$
– Henrik Schumacher
2 hours ago




$begingroup$
Would you please provide a small portion of the data table as an example? That would make live much easier for us.
$endgroup$
– Henrik Schumacher
2 hours ago




1




1




$begingroup$
You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
$endgroup$
– Henrik Schumacher
2 hours ago




$begingroup$
You may try something like FirstPosition[SSpecWavelength, _?(# > 1107. &)] to find the first position with a value larger than 1107..
$endgroup$
– Henrik Schumacher
2 hours ago




1




1




$begingroup$
In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
$endgroup$
– Henrik Schumacher
2 hours ago




$begingroup$
In general Position may take floating point numbers more literate than you. The value from the list could be 1107.0000001 or so but only the leading digits are shown. This difference may be small, but Position won't match 1107. with 1107.0000001.
$endgroup$
– Henrik Schumacher
2 hours ago












$begingroup$
FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
$endgroup$
– alonoid
2 hours ago




$begingroup$
FirstPosition works actually. But why does Position not work? The element in the list is exactly 1107.
$endgroup$
– alonoid
2 hours ago












$begingroup$
How do I only use the returned index number without the curly brackets? How do I remove the brackets?
$endgroup$
– alonoid
2 hours ago




$begingroup$
How do I only use the returned index number without the curly brackets? How do I remove the brackets?
$endgroup$
– alonoid
2 hours ago










1 Answer
1






active

oldest

votes


















4












$begingroup$

Given



data = {280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5};


you could use



data[[;; Position[data, 282.][[1, 1]]]]


or



data[[;; FirstPosition[data, 282.][[1]]]]


both return




{280., 280.5, 281., 281.5, 282.}




I recommend that you use the 2nd form; i.e., the one using FirstPosition



Now suppose data was



data = {280., 280.5, 281., 281.5, 282.0000001, 282.5, 283., 283.5, 284., 284.5};


Then, although



data[[5]]


prints out as




282.




Position[data, 282.][[1, 1]]


generates the error message



msg



To fix this you can write



Position[data, _?(Round[#, .1] == 282. &)]



{{5}}




The same change in its 2nd argument will fix the problem should FirstPostion be used in place of Position.






share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192080%2ffinding-the-index-of-a-specific-element-in-a-list%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4












    $begingroup$

    Given



    data = {280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5};


    you could use



    data[[;; Position[data, 282.][[1, 1]]]]


    or



    data[[;; FirstPosition[data, 282.][[1]]]]


    both return




    {280., 280.5, 281., 281.5, 282.}




    I recommend that you use the 2nd form; i.e., the one using FirstPosition



    Now suppose data was



    data = {280., 280.5, 281., 281.5, 282.0000001, 282.5, 283., 283.5, 284., 284.5};


    Then, although



    data[[5]]


    prints out as




    282.




    Position[data, 282.][[1, 1]]


    generates the error message



    msg



    To fix this you can write



    Position[data, _?(Round[#, .1] == 282. &)]



    {{5}}




    The same change in its 2nd argument will fix the problem should FirstPostion be used in place of Position.






    share|improve this answer









    $endgroup$


















      4












      $begingroup$

      Given



      data = {280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5};


      you could use



      data[[;; Position[data, 282.][[1, 1]]]]


      or



      data[[;; FirstPosition[data, 282.][[1]]]]


      both return




      {280., 280.5, 281., 281.5, 282.}




      I recommend that you use the 2nd form; i.e., the one using FirstPosition



      Now suppose data was



      data = {280., 280.5, 281., 281.5, 282.0000001, 282.5, 283., 283.5, 284., 284.5};


      Then, although



      data[[5]]


      prints out as




      282.




      Position[data, 282.][[1, 1]]


      generates the error message



      msg



      To fix this you can write



      Position[data, _?(Round[#, .1] == 282. &)]



      {{5}}




      The same change in its 2nd argument will fix the problem should FirstPostion be used in place of Position.






      share|improve this answer









      $endgroup$
















        4












        4








        4





        $begingroup$

        Given



        data = {280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5};


        you could use



        data[[;; Position[data, 282.][[1, 1]]]]


        or



        data[[;; FirstPosition[data, 282.][[1]]]]


        both return




        {280., 280.5, 281., 281.5, 282.}




        I recommend that you use the 2nd form; i.e., the one using FirstPosition



        Now suppose data was



        data = {280., 280.5, 281., 281.5, 282.0000001, 282.5, 283., 283.5, 284., 284.5};


        Then, although



        data[[5]]


        prints out as




        282.




        Position[data, 282.][[1, 1]]


        generates the error message



        msg



        To fix this you can write



        Position[data, _?(Round[#, .1] == 282. &)]



        {{5}}




        The same change in its 2nd argument will fix the problem should FirstPostion be used in place of Position.






        share|improve this answer









        $endgroup$



        Given



        data = {280., 280.5, 281., 281.5, 282., 282.5, 283., 283.5, 284., 284.5};


        you could use



        data[[;; Position[data, 282.][[1, 1]]]]


        or



        data[[;; FirstPosition[data, 282.][[1]]]]


        both return




        {280., 280.5, 281., 281.5, 282.}




        I recommend that you use the 2nd form; i.e., the one using FirstPosition



        Now suppose data was



        data = {280., 280.5, 281., 281.5, 282.0000001, 282.5, 283., 283.5, 284., 284.5};


        Then, although



        data[[5]]


        prints out as




        282.




        Position[data, 282.][[1, 1]]


        generates the error message



        msg



        To fix this you can write



        Position[data, _?(Round[#, .1] == 282. &)]



        {{5}}




        The same change in its 2nd argument will fix the problem should FirstPostion be used in place of Position.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        m_goldbergm_goldberg

        86.7k872196




        86.7k872196






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192080%2ffinding-the-index-of-a-specific-element-in-a-list%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

            Meter-Bus Содержание Параметры шины | Стандартизация |...