Looking for help in using structs in multiple functions

조회 수: 5 (최근 30일)
Maxwell Hasenauer
Maxwell Hasenauer 2017년 9월 13일
댓글: Arjun 2025년 1월 31일
I am trying to use structs, but I have no idea what a 0x1 struct is, and I am trying to add to the struct outside of a function, but I don't understand how they work. None of the websites have a good explanation of how to use the struct. Plus, I get an error when I use the dot method to add to it.
  댓글 수: 1
James Tursa
James Tursa 2017년 9월 13일
편집: James Tursa 2017년 9월 13일
A 0x1 struct is a struct that has size 0x1. That is, it is empty. Analogous to an empty double variable, e.g.,
>> x = zeros(0,1)
x =
Empty matrix: 0-by-1 <-- an empty double
>> s = struct([])
s =
0x0 struct array with no fields. <-- an empty struct
Please post your code with an explanation of what you are trying to do and we can help you.

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

답변 (1개)

Arjun
Arjun 2025년 1월 31일
I understand that you want to use 'struct' and you are particularly struggling with usage of 0x1 struct.
When you encounter a 0x1 struct in MATLAB, it indicates an empty struct array with zero rows and one column. This is just one way a struct can be considered empty. There are various other conditions under which a struct might be deemed empty, depending on its initialization and usage. For a comprehensive understanding of different scenarios where a struct can be classified as empty, you can refer to resources like the: https://www.mathworks.com/matlabcentral/fileexchange/45135-emptystruct
For a more comprehensive understanding of how to work with structs in MATLAB, you can refer to the: https://www-test1.mathworks.com/help/releases/R2017a/matlab/ref/struct.html
If you're encountering an error message related to using the dot operator with structs in MATLAB, especially when trying to insert fields into an empty struct, you might find this https://www.mathworks.com/matlabcentral/answers/304616-inserting-fields-into-an-empty-structure helpful. It provides insights and solutions for properly adding fields to an empty struct, which can resolve common issues related to struct manipulation.
Additionally, you can refer to this MATLAB Answer: https://www.mathworks.com/matlabcentral/answers/742937-how-to-make-a-1x0-struct-array for even better clarity.
The above resources will provide you with good starting knowledge of an empty struct and how you can start manipulating them and also some insights about the error message that you are currently facing.
I hope this will help!
  댓글 수: 2
Stephen23
Stephen23 2025년 1월 31일
편집: Stephen23 2025년 1월 31일
"For a comprehensive understanding of different scenarios where a struct can be classified as empty, you can refer to resources like the"
That is not a MATLAB resource, that is someone's FEX submission where they write anything they want, including using terms that diverge misleadingly from the MATLAB documentation.
A structure is just like any other array: it is empty when one of its dimensions is zero, i.e. it contains zero elements.
For a truly comprehensive explanation of empty arrays:
It is curious how the AI refers to the 2017 documentation. Perhaps that is all it knows.
Arjun
Arjun 2025년 1월 31일
In this answer a link to: https://www.mathworks.com/matlabcentral/fileexchange/45135-emptystruct was provided in the accepted answer and thus I mentioned it here.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by