Can't iterate over field of a struct matlabApply a function to all fields of an array of structs in MatlabAccess complex matlab struct with function/stringHow can I create a Matlab struct array from scipy.io?Matlab loop to assign rows to cell arrayIterating through Struct MATLABReshaping nested struct array to cell array having elements with different sizesCombining Matlab files using structsPlotting structure array in MatlabMATLAB: How to use cellfun with a struct?Matlab: calculating the mean of an array nested in a struct

Get the encrypted payload from an unencrypted wrapper PDF document

Do the villains know Batman has no superpowers?

Why are Fuji lenses more expensive than others?

how to parse json to list?

Can I separate garlic into cloves for storage?

Do liquid propellant rocket engines experience thrust oscillation?

How do rulers get rich from war?

Why does Canada require a minimum rate of climb for ultralights of 300 ft/min?

Who are the people reviewing far more papers than they're submitting for review?

Integrability of log of distance function

Is it safe to unplug a blinking USB drive after 'safely' ejecting it?

Madrid to London w/ Expired 90/180 days stay as US citizen

What is the word for a person who destroys monuments?

Escape the labyrinth!

Should I inform my future product owner that there is a good chance that a team member will leave the company soon?

Does battery condition have anything to do with macbook pro performance?

Temporarily moving a SQL Server 2016 database to SQL Server 2017 and then moving back. Is it possible?

The relationship of noch nicht and the passive voice

Why are two-stroke engines nearly unheard of in aviation?

4h 40m delay caused by aircraft inspection, Norwegian refuses EU 261/2004 compensation because it turned out there was nothing wrong with the aircraft

Is a global DNS record a security risk for phpMyAdmin?

Did slaves have slaves?

Find all files in directories named foo

How to ask a man to not take up more than one seat on public transport while avoiding conflict?



Can't iterate over field of a struct matlab


Apply a function to all fields of an array of structs in MatlabAccess complex matlab struct with function/stringHow can I create a Matlab struct array from scipy.io?Matlab loop to assign rows to cell arrayIterating through Struct MATLABReshaping nested struct array to cell array having elements with different sizesCombining Matlab files using structsPlotting structure array in MatlabMATLAB: How to use cellfun with a struct?Matlab: calculating the mean of an array nested in a struct






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am working currently with matlab and I try to extract some data from a struct that I have, but it seems it is not as easy I thought it would be.



structExample = 1x100000
fieldnames(structExample)

ans =

6×1 cell array

'a'
'b'
'c'
'd'
'e'
'f'


I am interested in the values saved in field 'b'.
When I type structExample.b it prints out all the values, but when I do



values = structExample.b


It only saves the first values ([1.2,5.33]) . 'b' has double values for example




[1.2,5.33], 1x86double, 1x120double ...




My aim is to be able to plot them with cdfplot()

So I thought maybe iterate over all values in the field and save them in a separate array. But I don't know how to iterate through it, since structExample.b only takes the first values. Any ideas?



Edit:

structExample.b(3) returns




Expected one output from a curly brace or dot indexing expression, but
there were 41817 results.











share|improve this question






























    1















    I am working currently with matlab and I try to extract some data from a struct that I have, but it seems it is not as easy I thought it would be.



    structExample = 1x100000
    fieldnames(structExample)

    ans =

    6×1 cell array

    'a'
    'b'
    'c'
    'd'
    'e'
    'f'


    I am interested in the values saved in field 'b'.
    When I type structExample.b it prints out all the values, but when I do



    values = structExample.b


    It only saves the first values ([1.2,5.33]) . 'b' has double values for example




    [1.2,5.33], 1x86double, 1x120double ...




    My aim is to be able to plot them with cdfplot()

    So I thought maybe iterate over all values in the field and save them in a separate array. But I don't know how to iterate through it, since structExample.b only takes the first values. Any ideas?



    Edit:

    structExample.b(3) returns




    Expected one output from a curly brace or dot indexing expression, but
    there were 41817 results.











    share|improve this question


























      1












      1








      1








      I am working currently with matlab and I try to extract some data from a struct that I have, but it seems it is not as easy I thought it would be.



      structExample = 1x100000
      fieldnames(structExample)

      ans =

      6×1 cell array

      'a'
      'b'
      'c'
      'd'
      'e'
      'f'


      I am interested in the values saved in field 'b'.
      When I type structExample.b it prints out all the values, but when I do



      values = structExample.b


      It only saves the first values ([1.2,5.33]) . 'b' has double values for example




      [1.2,5.33], 1x86double, 1x120double ...




      My aim is to be able to plot them with cdfplot()

      So I thought maybe iterate over all values in the field and save them in a separate array. But I don't know how to iterate through it, since structExample.b only takes the first values. Any ideas?



      Edit:

      structExample.b(3) returns




      Expected one output from a curly brace or dot indexing expression, but
      there were 41817 results.











      share|improve this question














      I am working currently with matlab and I try to extract some data from a struct that I have, but it seems it is not as easy I thought it would be.



      structExample = 1x100000
      fieldnames(structExample)

      ans =

      6×1 cell array

      'a'
      'b'
      'c'
      'd'
      'e'
      'f'


      I am interested in the values saved in field 'b'.
      When I type structExample.b it prints out all the values, but when I do



      values = structExample.b


      It only saves the first values ([1.2,5.33]) . 'b' has double values for example




      [1.2,5.33], 1x86double, 1x120double ...




      My aim is to be able to plot them with cdfplot()

      So I thought maybe iterate over all values in the field and save them in a separate array. But I don't know how to iterate through it, since structExample.b only takes the first values. Any ideas?



      Edit:

      structExample.b(3) returns




      Expected one output from a curly brace or dot indexing expression, but
      there were 41817 results.








      matlab






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 14:32









      CroatiaHRCroatiaHR

      929 bronze badges




      929 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2
















          When you access a field of a structure array, it returns a comma-separated list of values. By default, only the first value in a list will be assigned to a single variable. If you want to capture all of these values, you have to collect them using [] (for a normal array) or (for a cell array). Since you are dealing with different-sized sets of data in each structure, you will need to use a cell array:



          values = structExample.b;


          So, values1 will contain [1.2,5.33], values2 will contain 1x86 double, etc..



          For the case where you want to iterate over the structure array, you have to index array elements and fields in the correct order. You should index the element first (which gives you a single structure element from the array), then index the field you want:



          value = structExample(3).b; % Field b of the third array element


          For the additional case where you want to collect a field from an indexed subset of elements in your structure array, you have to combine the indexing and collection schemes from above. For example:



          values = structExample([structExample.a] == 1).b;


          This will collect all a field values from structExample into an array, find a logical index for where they equal 1, index the structExample array with that logical array, then collect the values of field b from that subarray and place them in a cell array.






          share|improve this answer



























          • If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

            – CroatiaHR
            Mar 28 at 14:52











          • the problem from iterating is that when I call length(structExample.b) it says that it has too many values

            – CroatiaHR
            Mar 28 at 14:55






          • 1





            As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

            – obchardon
            Mar 28 at 15:01










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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/4.0/"u003ecc by-sa 4.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%2fstackoverflow.com%2fquestions%2f55400183%2fcant-iterate-over-field-of-a-struct-matlab%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









          2
















          When you access a field of a structure array, it returns a comma-separated list of values. By default, only the first value in a list will be assigned to a single variable. If you want to capture all of these values, you have to collect them using [] (for a normal array) or (for a cell array). Since you are dealing with different-sized sets of data in each structure, you will need to use a cell array:



          values = structExample.b;


          So, values1 will contain [1.2,5.33], values2 will contain 1x86 double, etc..



          For the case where you want to iterate over the structure array, you have to index array elements and fields in the correct order. You should index the element first (which gives you a single structure element from the array), then index the field you want:



          value = structExample(3).b; % Field b of the third array element


          For the additional case where you want to collect a field from an indexed subset of elements in your structure array, you have to combine the indexing and collection schemes from above. For example:



          values = structExample([structExample.a] == 1).b;


          This will collect all a field values from structExample into an array, find a logical index for where they equal 1, index the structExample array with that logical array, then collect the values of field b from that subarray and place them in a cell array.






          share|improve this answer



























          • If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

            – CroatiaHR
            Mar 28 at 14:52











          • the problem from iterating is that when I call length(structExample.b) it says that it has too many values

            – CroatiaHR
            Mar 28 at 14:55






          • 1





            As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

            – obchardon
            Mar 28 at 15:01















          2
















          When you access a field of a structure array, it returns a comma-separated list of values. By default, only the first value in a list will be assigned to a single variable. If you want to capture all of these values, you have to collect them using [] (for a normal array) or (for a cell array). Since you are dealing with different-sized sets of data in each structure, you will need to use a cell array:



          values = structExample.b;


          So, values1 will contain [1.2,5.33], values2 will contain 1x86 double, etc..



          For the case where you want to iterate over the structure array, you have to index array elements and fields in the correct order. You should index the element first (which gives you a single structure element from the array), then index the field you want:



          value = structExample(3).b; % Field b of the third array element


          For the additional case where you want to collect a field from an indexed subset of elements in your structure array, you have to combine the indexing and collection schemes from above. For example:



          values = structExample([structExample.a] == 1).b;


          This will collect all a field values from structExample into an array, find a logical index for where they equal 1, index the structExample array with that logical array, then collect the values of field b from that subarray and place them in a cell array.






          share|improve this answer



























          • If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

            – CroatiaHR
            Mar 28 at 14:52











          • the problem from iterating is that when I call length(structExample.b) it says that it has too many values

            – CroatiaHR
            Mar 28 at 14:55






          • 1





            As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

            – obchardon
            Mar 28 at 15:01













          2














          2










          2









          When you access a field of a structure array, it returns a comma-separated list of values. By default, only the first value in a list will be assigned to a single variable. If you want to capture all of these values, you have to collect them using [] (for a normal array) or (for a cell array). Since you are dealing with different-sized sets of data in each structure, you will need to use a cell array:



          values = structExample.b;


          So, values1 will contain [1.2,5.33], values2 will contain 1x86 double, etc..



          For the case where you want to iterate over the structure array, you have to index array elements and fields in the correct order. You should index the element first (which gives you a single structure element from the array), then index the field you want:



          value = structExample(3).b; % Field b of the third array element


          For the additional case where you want to collect a field from an indexed subset of elements in your structure array, you have to combine the indexing and collection schemes from above. For example:



          values = structExample([structExample.a] == 1).b;


          This will collect all a field values from structExample into an array, find a logical index for where they equal 1, index the structExample array with that logical array, then collect the values of field b from that subarray and place them in a cell array.






          share|improve this answer















          When you access a field of a structure array, it returns a comma-separated list of values. By default, only the first value in a list will be assigned to a single variable. If you want to capture all of these values, you have to collect them using [] (for a normal array) or (for a cell array). Since you are dealing with different-sized sets of data in each structure, you will need to use a cell array:



          values = structExample.b;


          So, values1 will contain [1.2,5.33], values2 will contain 1x86 double, etc..



          For the case where you want to iterate over the structure array, you have to index array elements and fields in the correct order. You should index the element first (which gives you a single structure element from the array), then index the field you want:



          value = structExample(3).b; % Field b of the third array element


          For the additional case where you want to collect a field from an indexed subset of elements in your structure array, you have to combine the indexing and collection schemes from above. For example:



          values = structExample([structExample.a] == 1).b;


          This will collect all a field values from structExample into an array, find a logical index for where they equal 1, index the structExample array with that logical array, then collect the values of field b from that subarray and place them in a cell array.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 28 at 15:01

























          answered Mar 28 at 14:38









          gnovicegnovice

          120k13 gold badges238 silver badges342 bronze badges




          120k13 gold badges238 silver badges342 bronze badges















          • If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

            – CroatiaHR
            Mar 28 at 14:52











          • the problem from iterating is that when I call length(structExample.b) it says that it has too many values

            – CroatiaHR
            Mar 28 at 14:55






          • 1





            As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

            – obchardon
            Mar 28 at 15:01

















          • If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

            – CroatiaHR
            Mar 28 at 14:52











          • the problem from iterating is that when I call length(structExample.b) it says that it has too many values

            – CroatiaHR
            Mar 28 at 14:55






          • 1





            As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

            – obchardon
            Mar 28 at 15:01
















          If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

          – CroatiaHR
          Mar 28 at 14:52





          If I may add a further question, is there a neat way to save data based on a value from 'a'. Example: values1 = [structExample.b] if 'a' == 1

          – CroatiaHR
          Mar 28 at 14:52













          the problem from iterating is that when I call length(structExample.b) it says that it has too many values

          – CroatiaHR
          Mar 28 at 14:55





          the problem from iterating is that when I call length(structExample.b) it says that it has too many values

          – CroatiaHR
          Mar 28 at 14:55




          1




          1





          As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

          – obchardon
          Mar 28 at 15:01





          As explained by gnovice you need to encapsulate the data in an array. So length([structExample.b]) should work

          – obchardon
          Mar 28 at 15:01








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


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

          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%2fstackoverflow.com%2fquestions%2f55400183%2fcant-iterate-over-field-of-a-struct-matlab%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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?