Possible bug in struct2table()
Show older comments
But if I have an array of that structure it works just fine.
Try the following code:
load singleStruct.mat
% This ends up in error
try
myTBL = struct2table(singleStruct);
catch
disp('I told you this ends up in error.');
end
% This wont end up in Error
structArray(1) = singleStruct;
structArray(2) = singleStruct;
myTBL = struct2table(structArray);
I have attached the singleStruct.mat for you guys to try.
Any work around?
Well, I usually have an array of those structure, this is really an special case that it is only one.
1 Comment
Steven Lord
on 6 Apr 2016
What is the FULL text of the error message?
Accepted Answer
More Answers (1)
Lukas
on 26 Apr 2017
As this error only occurs with (1x1) structs, there is a simple workaroud. To convert a struct into a table, use the following code:
largeStruct = repmat(struct,2,1);
table = struct2table(largeStruct);
table = table(1,:);
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!