For example, I have:
A = ['apple','banana','strawberry','orange']
B = ['2','1','1','4']
I want:
struct_foo =
apple: 2
banana: 1
strawberry: 1
orange: 4
In other words, I want a struct whose fields are elements in A and the value of those fields are elements in B.
I can do this easily with a for loop…, but is there an easier way to do this?
You can use the command
cell2struct. Note the curly brackets when defining A and B. Also, you may want to remove the quotation marks around the numbers in B if the values should be numeric.