Last change
on this file since 1134 was
1095,
checked in by sommeria, 4 years ago
|
reading mat files added, +-fixed,OpenDAP improved
|
File size:
1.5 KB
|
Rev | Line | |
---|
[1095] | 1 | %'mat2struct': read a matlab file .mat as a structure similar to the output |
---|
| 2 | %of nc2struct |
---|
| 3 | %---------------------------------------------------------------------- |
---|
| 4 | function Field=mat2struct(filename,ListFieldName) |
---|
| 5 | |
---|
| 6 | Field=load(filename);%case of .mat data file |
---|
| 7 | if ~exist('ListFieldName','var') |
---|
| 8 | ListFieldName=fieldnames(Field); |
---|
| 9 | end |
---|
| 10 | ivar=0; |
---|
| 11 | Field.DimValue=[]; |
---|
| 12 | Field.ListGlobalAttribute={}; |
---|
| 13 | Field.ListVarName={}; |
---|
| 14 | ndim=0; |
---|
| 15 | for ilist=1:numel(ListFieldName) |
---|
| 16 | if isnumeric(Field.(ListFieldName{ilist})) && numel(Field.(ListFieldName{ilist}))>=2 |
---|
| 17 | ivar=ivar+1; |
---|
| 18 | Field.ListVarName=[Field.ListVarName ListFieldName{ilist}]; |
---|
| 19 | ndim_var=0; |
---|
| 20 | for idim=1:ndims(Field.(ListFieldName{ilist})) |
---|
| 21 | sizevar=size(Field.(ListFieldName{ilist}),idim); |
---|
| 22 | if sizevar>1% avoid singleton dimensions |
---|
| 23 | ndim_var=ndim_var+1; |
---|
| 24 | prevdim_index=find(Field.DimValue==sizevar);%look for the same value of dimension |
---|
| 25 | if isempty(prevdim_index)% new dimension detected |
---|
| 26 | ndim=ndim+1; |
---|
| 27 | Field.DimValue(ndim)=sizevar; |
---|
| 28 | Field.ListDimName{ndim}=num2str(sizevar); |
---|
| 29 | Field.VarDimName{ivar}{ndim_var}=Field.ListDimName{ndim}; |
---|
| 30 | else |
---|
| 31 | Field.VarDimName{ivar}{ndim_var}=Field.ListDimName{prevdim_index}; |
---|
| 32 | end |
---|
| 33 | end |
---|
| 34 | end |
---|
| 35 | Field.VarType(ivar)=5;%for double variable |
---|
| 36 | else |
---|
| 37 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute ListFieldName{ilist}]; |
---|
| 38 | end |
---|
| 39 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.