Converting .sb(.txt) file to excel file

2 views (last 30 days)
Arnab Paul
Arnab Paul on 6 Feb 2023
Answered: Smit on 7 Feb 2023
I have this code below which suppose to convert .sb extension file to excel file. but it is showing error as
Error using fieldnames
Invalid input argument of type 'cell'. Input must be a structure or a Java or COM object.
Error in sb2exl (line 4)
fields = fieldnames(data);
For the convenience of attaching the file, I have converted it to .txt file
data = readsb('6bbb44bb68_archive01.sb');
%preprocess the datato reformat into table format
fields = fieldnames(data);
for i = 1:numel(fields)
field = fields{i};
T.(field) = data.(field)(:);
end
writetable(T, '6bbb44bb68_archive01.xlsx');
Any help is appriciated.

Accepted Answer

Smit
Smit on 7 Feb 2023
Hi Arnab,
I understand you are trying to convert a “.sb” file to an Excel file. You are using the “readsb” function to read the data from the file and are getting an error while pre-processing the data from the “readsb” function.
The error suggests that the data read from “readsb” is in a cell format, but the function “fieldnames” expects a structure, Java, or COM object input.
The “readsb” function can take other inputs which specify whether to return the data as a structure.
You can get the “.sb” file data in a struct using the following command
readsb('6bbb44bb68_archive01.sb', 'MakeStructure', 1);
You can refer this link for more information on the “readsb” function.
This should resolve the error. However, you might need to use the “struct2table” function while writing the Excel file.
You can do so in the following manner
writetable(struct2table(T), '6bbb44bb68_archive01.xlsx');

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!