why readtable create field "D" in the struct "D1"?

Luca Re · Jun 19, 2023 · 2.1K views
Question
function D1=TEST() D=readtable('test.txt','delimiter',','); save canc.tset D D1=load('canc.tset',"-mat") end i access it using D1.D... it's possibile to avoid "D" field?    
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 14, 2026

If there is only one variable in the MAT file (regardless of its extension) and you do not know/care what its name is:

 

C = struct2cell(load(..));
assert(isscalar(C),'Only one array can be LOADed')
T = C{1}

If the variable name is known in advance, e.g. "D"

S = load(..)
T = S.D

 

Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!