Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: Problem with structures

  1. Sep 2, 2011 #1
    Hi All,

    I've written some code in Matlab that calculates a number of parameters and saves the data to a structure. A portion of the code is shown below:

    uniqueName = genvarname(date);
    plant(id).(uniqueName) = {date avgHeight avgVol};
    .
    The various parameters such as avgHeight etc. are defined earlier in the program. The confusing thing is that the code works fine when 'id' is a single digit number. However, when 'id' >= 10, the program returns the following error:
    .
    ??? Insufficient outputs from right hand side to satisfy comma separated
    list expansion on left hand side. Missing [] are the most likely cause.
    .
    I don't understand the error message and don't know what to do next.
    Any help I receive will be greatly appreciated.
    Thanks very much for your time,
    Craig
     
  2. jcsd
  3. Sep 2, 2011 #2

    jhae2.718

    User Avatar
    Gold Member

    You might consider building a class instead of using a struct.

    As for the error, there's not much to go on without having more code.
     
  4. Sep 2, 2011 #3

    Pythagorean

    User Avatar
    Gold Member

    As far as I know, a structure is a type of class in MATLAB:


    http://www.mathworks.com/help/techdoc/matlab_oop/brh2rgw.html#brgljyu [Broken]

    craigpmorgan, try:

    plant(str2double(id)).(uniqueName) = {date avgHeight avgVol};

    so that you convert id to a number in case it's a string. It seems to me like it's interpreting 10 (for instance) as a 1 and 0 in a string array, rather than a single 10 in a number array.
     
    Last edited by a moderator: May 5, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab: Problem with structures
  1. MatLab structures (Replies: 5)

Loading...