-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there a equivalent thing as Matlab struct? #1263
Comments
No, we don't have anything exactly equivalent to a matlab struct array. If the number of fields is very large, a hash table of symbols makes sense. If the number of fields is small, one could define a type with all the needed field names and use that. Or, the "julia way" is to define a |
Thanks for the clarification. i think the StructArray type could be base on dictionary type or just a array of Tuple{String, Any}, hope it would be sit in the standard library soon! |
I would strongly consider using either just a Dict or a composite type. The Matlab struct business is a really kind of a compromise that's somewhere between those two and not obviously better than either at any particular job. I have a hard time thinking of use cases where a StructArray would be better. Keep in mind that "no slower than matlab's struct arrays" still means "much slower than Julia's composite types" and possibly even "slower than Julia's dicts" since both of those are quite fast and well-tuned. |
The matlab struct array is a really wacky data structure. It's fine when you just want a small dictionary with string keys, but its full behavior is crazy. I've implemented it before and we didn't know whether to laugh or cry. I would think hard about what the use cases are before implementing this. |
To me a main attraction of the Matlab struct is the easy access into hierarchical structs, e.g. a.b.c.d If it's practical to implement with composite types Julia code would look the same, but if it's necessary to resort to dictionaries the access pattern would instead be a["b"]["c"]["d"] which is comparatively painful both to write and read. |
Nesting composite types is no problem. I agree that |
The actual nesting of composite types is no problem but in situations where you need to nest dozens of different types to represent your data, defining the types can be a substantial effort. |
i think the matlab structure is some kind of syntax suger of dictionary. if you use a composite type then you cann't dynamicly add or delete it's fields or using Struct.(string expression) to generate hierarchical structs. if you use a straight dictionary then you get ugly and tedious code. matlab struct could be use to represent dynamic data structures clean and clear. for example, all possible experimental data organized in hierarchy as the standard data structure. then the subsequent analysis code could adapt to different subset of data fields through checking existence of particular relevent fields. |
If the |
As far as I know, |
I rather would like it to be, but that presents a number of implementation and performance issues, so it may take some time before that can be done. |
Since this decision is no longer about the original subject at all, I'm closing it and opening a new issue. |
Has any work been one on this ? e.g. , is there now any functionality in julia that allows the use of MATLAB like structures? |
@huckl3b3rry87 See #16580 |
I am very interested in Julia Language and just begin to learn, and want to know if there is something like Matlab Structure, or those kind of feature or Structure Arrays could be implemented in some kind of dynamic modification of Type definitions?
The text was updated successfully, but these errors were encountered: