MATLAB: How to create a structure

structure

I have a data set (DATA) that contains 100 stations with daily prices and demand.
Using this code I can have 100 stations with the data that belong to each of them.
Can you help me to fix the code??
N=length(DATA(:,1))
for i=1:N
x=DATA(i,1)
station=['S', num2str(x)]
station=[station;DATA(i,:)]
end

Best Answer

You can use num2cell to split the data into cell array by column.
You can construct an array of field names in a couple of ways, including using sprintfc or string objects with the + (concatenation) operation.
Once you have both of the above you can use cell2struct to create your structure.
However we wonder why you are not just leaving the data in the numeric matrix, as that is the fastest and smallest storage?