MATLAB: Do I get the error: “Attempt to reference field of non-structure array”

error

I refer to a function using a dataset transferred from stata, and I get the following message:
"Attempt to reference field of non-structure array.
Error in livsindkomst (line 26)
data(find(st_dataset.udd~=uddtype),:)=[];
end"
st_dataset is the data transferred from stata, but it seems like there is a problem refering to this data. Specifically, my aim is to check whether the variable udd equals the variable uddtype, and delete it if it does not. I define the variable uddtype in my programme.

Best Answer

"Is there an easy way to make this conversion". If this conversion refers to converting an empty double into an empty struct with the correct fields:
if isempty(st_dataset) && ~isstruct(st_dataset)
st_dataset = struct('udd', {}, 'otherfield', {}); %add as many fields as necessary
end
If you have the list of field names as a string in a cell array, it may be easier to use convert an empty cell array into an empty structure:
fields = {'udd', 'otherfield'}; %add as many fields as necessary
if isempty(st_dataset) && ~isstruct(st_dataset)
st_dataset = cell2struct(cell(0, 0, numel(fields)), fields, 3);
end