I am attempting to use writestruct() to save a structure to a .csv file, using version 2020b.
I started by calling writestruct as follows: writestruct(S,fullname), where S is the structure, and fullname is fullname=[path filename], which was obtained via uiputfile.
When I run this, I receive this error: Expected S to be a scalar.
I figured that the structure S could be anything as long as it is a structure, what am I missing?
Thank you!!

댓글 수: 2

Rod - try running the following in your command window
which writestruct -all
What does this return? Just a single reference to the writestruct function or something else? Also, have you tried the examples at writestruct examples to see if they work for you? If they do, you may want to post some of the code that shows us what your structure looks like and how you are calling the function.
Jakob
Jakob 2021년 2월 10일
Have you tried struct2table() and then export the table with writetable()?

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 10일

1 개 추천

No, you must use a scalar structure, not a non-scalar structure.
S(1).this = 'that';
writestruct(S, 'junkfile.xml');
%scalar okay
S(2).this = 'the other';
writestruct(S, 'junkfile.xml');
Expected S to be a scalar.
%not okay

댓글 수: 3

Rod Lopez
Rod Lopez 2021년 2월 10일
This is exactly how I have it set up, so no wonder it does not work. I have a structure set up as follows in app designer:
app.Recipe(n).___ stores properties defined by the user, where ____ is a set of fields defined for each "n".
I will try struct2table followed by writetable unless you guys can think of anything else I might try.
Thank you!
Walter Roberson
Walter Roberson 2021년 2월 10일
struct2table() sounds plausible.
Rod Lopez
Rod Lopez 2021년 2월 15일
As a quick update for anyone who runs into these issues:
Since I needed to export a non-scalar structure to excel, and a few fields are matricies of different sizes, I first used mat2str to consolidate those fields down to what will be a single cell in the table. It is not ideal but at least this way there aren't additional columns in the table for each additional row of one of these fields.
Thank you!
-Rod

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 2월 10일

댓글:

2021년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by