Converting .sb(.txt) file to excel file

조회 수: 2 (최근 30일)
Arnab Paul
Arnab Paul 2023년 2월 6일
답변: Smit 2023년 2월 7일
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.

채택된 답변

Smit
Smit 2023년 2월 7일
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');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by