MATLAB: Struct to numeric variable

MATLABstruct

Hi,
Sorry but this is a really simple question. I have a struct (3 fields and 446 elements) and I'm trying to access a a specific field and assign it to a workspace variable. I used the following syntax:
new_var = structname.fieldname
However, when I do this, I just get the first row of data in my field name. I want all the rows in structname.fieldname to be assigned to new_var.
When I try structname(1).fieldname or structname(2).fieldname – i get the corresponding row data only. I've tried the following: structname.fieldname(:,1) but get the following error message:
Expected one output from a curly brace or dot indexing expression, but there were 446 results.
Also tried structname(:).fieldname but again, just get the first row of data in fieldname – I'd like all 446 elements.
I know this is very simple but I just can't figure it out!

Best Answer

Apparently you have a 446x1 or 1x446 structure array, where the field in question contains a row vector. To concatenate all of the row vectors for that field you can use a comma-separated list:
new_var = vertcat(structname.fieldname)
Read how it works:
"Basically structname.AccRang extracted to be a variable..."
What you explain is consistent with a non-scalar structure where one field contains row vectors. So before being "extracted" to some variable, those row vectors need to be concatenated togther (they are NOT stored all as one matrix within the non-scalar structure), just like you would concatenate together any other set of row vectors to create one matrix.