MATLAB: Convert a txt file to a structure

cell to structure

Hello, I read and text scanned a text file into a variable. This variable (1×2 cell) now contains 2 cell arrays each of these cell arrays is a 31×1 cell. One of them contain the names and the other the values. how do I assign each name to its corresponding value? Here is my code but its not working:
clear all;
clc;
PVData = 'w:\Users\james\Documents\MATLAB\readfile.txt';
fid=fopen(PVData);
PVRead=textscan(fid,'%s %f %*[^\n]','delimiter','=','EmptyValue',nan);
fclose(fid);
names = PVRead(1);
values = PVRead(2);
structarray = cell2struct(values, names, 2);

Best Answer

Method one: cell2struct:
cell2struct(num2cell(PVRead{2}),PVRead{1},1)
Method two: struct:
C = [PVRead{1},num2cell(PVRead{2})].'
S = struct(C{:})
Tested:
>> PVRead = {{'anna';'bob';'cat'},[1;2;3]};
>> C = [PVRead{1},num2cell(PVRead{2})].';
>> S = struct(C{:})
S =
scalar structure containing the fields:
anna = 1
bob = 2
cat = 3
>> S = cell2struct(num2cell(values),names,1)
S =
scalar structure containing the fields:
anna = 1
bob = 2
cat = 3