Looking for help in using structs in multiple functions
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
James Tursa
el 13 de Sept. de 2017
Editada: James Tursa
el 13 de Sept. de 2017
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.
Respuestas (1)
Arjun
el 31 de En. de 2025
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 comentarios
Stephen23
el 31 de En. de 2025
Editada: Stephen23
el 31 de En. de 2025
"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
el 31 de En. de 2025
While answering this question, I took help of this answer: https://www.mathworks.com/matlabcentral/answers/122057-how-to-create-an-empty-struc-with-fields-of-a-given-struct
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.
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!