How to concatenate multidimensional struct arrays
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi All, I have:
A = 1 * x array with k properties (i.e., fieldnames)
B = 1 * y array with (correspondingly same) k properties
How can I concatenate A and B to give C, such that C = 1 * (x+y) array with (correspondingly same) k properties.
Thank you in advance.
4 Commenti
Guillaume
il 15 Mag 2017
Well, this is even more confusing. From the error message you mention and from your comment above, it would appear that A and B are instances of classes which is yet another data type completely different from structures or cell arrays.
If that is the case, we need to see the definition of the classes (at the very least the property bit and the class hierarchy).
Risposta accettata
Guillaume
il 15 Mag 2017
Right, so you do have instances of classes, A of class segment and B of class segment2 (poor naming) in package elements. Several questions:
- Any reason for the two different classes. Can't A and B be instances of the same class. That way all your problem about concatenation go away.
- If A and B must be instances of different classes, then what class should the concatenation be? Instance of segment, instance of segment2 or instance of some other class? If there's no reason for selecting one over the other, then there is something wrong with your class design and we're better off working on fixing that design than working on getting the concatenation to work.
This help page details the rules for concatenation of objects. In theory, for the concatenation to work, all you need to do is provide a converter in each class (but see my point above).
You can indeed derive both classes from a base class derived from matlab.mixin.Heterogeneous, which would also enable the concatenation but you still have to define a hierarchy between all these classes. Considering the poor naming of the classes, that hierarchy is not obvious at the moment.
2 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Construct and Work with Object Arrays in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!