MATLAB: How does one create a dataset from a large array and subsequently name the variables

datasetMATLABvariable namesvarnames

I have a body data array read from a excel file: 9000-by-130. I also have the header line read from the same file: 1-by-130. I am trying to create a 900-by-130 dataset from the data array while using the elements of the header line array as variable names.
data = <9000x130 dataset>
headers = <1x130 cell>
The issue I'm having is…
D = dataset(array(:));
…just creates a 9000-by-1 dateset!? So, for example,
for i = 1:size(headers,2)
dataSet.Properties.VarNames{i} = headers{i};
end
…cannot find variables to match elements in headers{i}.
The only solution is to enter the variables and the names manually 130 times!
dataSet = dataset(data(:,1),data(:,2)...data(:,130),'VarNames',{'Var1','Var2',...,'KillMeNow'});
Surely there's a simpler way. Is there?

Best Answer

Tolulope, your question is not entirely clear. You show
data = <9000x130 dataset>
headers = <1x130 cell>
and it's not clear if that's what you have, or if that's what you want.
If that's what you have, and headers is a 1x130 cell array of strings, why does
data.Properties.VarNames = headers
not work? What does, "cannot find variables to match elements in headers{i}" mean?
You have an Excel file. You have said that you cannot use the dataset constructor to read the file and get the dataset array you want. It's not clear why that would be. Perhaps the header line is not in the obvuious place. The above should solve that.
This
D = dataset(array(:));
passes a column vector to the dataset constructor, so it's not unexpected that it creates a (something)x1 dataset array. It's not clear to me what "array" is, so it's impossible to know exactly what "something" is, or what you intended to do with that line.
If you have a 9000x130 numeric array, and a 1x130 cell array of strings, then as described in the help for dataset, you can do this:
x = rand(10,5);
d = dataset({X,names{:}})
Or, you can use use num2cell to split your numeric array up columnwise:
x = rand(10,5);
y = num2cell(x,1);
d = dataset(y{:},'VarNames',names)
If you have a very recent version of MATLAB, you can use the mat2dataset function (I can't recall if this exists in R2012a, but it definitely does in R2012b).
Hope this helps.