0

I'm trying to create a structure array c as below:

       c(i).j.k = something;       

I want to have a structure array inside a structure array, so c has two labels, i and j, however I am having difficulty in doing this and keep getting an error:

Unexpected MATLAB expression.

Any help on how to do this is very much appreciated.

ChuNan
  • 1,131
  • 2
  • 11
  • 27
Wooster
  • 105
  • 1
  • 8
  • Okay, thanks for the tip! I'm more into maths than programming, so indices are automatically i j and k for me! – Wooster Jul 22 '14 at 21:08
  • what is the error you are getting? what have you tried? – Shai Jul 22 '14 at 21:09
  • Have added the error to the post, I just get unexpected matlab expression – Wooster Jul 22 '14 at 21:10
  • I have just tried that, unfortunately it did not make a difference – Wooster Jul 22 '14 at 21:13
  • i, and j are both integers and k is a string for me at the moment. Thanks for your help! – Wooster Jul 22 '14 at 21:16
  • Nothing looks suspicious thus far, maybe looking at the code where you are generating `i`, `j` and `k` might help solve the issue. – Divakar Jul 22 '14 at 21:29
  • @Divakar I've added the full code to the post, thanks again, this is much appreciated – Wooster Jul 22 '14 at 21:33
  • It may seem strange that I just have a 1 there at the moment, however I need c to be in this form for another function I am using elsewhere – Wooster Jul 22 '14 at 21:33
  • @Divakar See the above comment, sorry I posted that quickly! – Wooster Jul 22 '14 at 21:36
  • That's done it! Thank you. If you want to make it into an answer I can accept it – Wooster Jul 22 '14 at 21:41
  • Ok, so I think the way these labels, which are technically called as the fieldnames, mustn't have names starting with numerals, like `1` in your case. You can do `L1` or `L2`, etc. though, but not `1L` or `2L`. It's the same when you try to name variable starting with numerals, won't work. – Divakar Jul 22 '14 at 21:41
  • Sorry I spoke too soon on that, see my comment just above this one. – Divakar Jul 22 '14 at 21:42
  • and seems like its a well-discussed topic with programming in general - http://stackoverflow.com/questions/342152/why-cant-variable-names-start-with-numbers – Divakar Jul 22 '14 at 21:49

0 Answers0