Creating an array of structs and using the field directly?
Mostra commenti meno recenti
Hey guys. I'm wondering if there is a workaround for doing something like this:
a = {[struct('field',1) struct('field',2)].field}
which works in octave but not in matlab ("invalid syntax at '.'. Possibly a ')', ']' or '}' is missing"), I have to use a temporary variable. This is quite annoying. Is there a workaround?
Thanks!
Risposta accettata
Più risposte (1)
Jan
il 19 Nov 2015
0 voti
As long as you insist on using standard struct : No, there is no workaround. Using a temporary variable is not a big deal and does not waste additional resources.
You can create your own object class, which solves the problem. But this will be less efficient.
3 Commenti
Jan Kappen
il 19 Nov 2015
Jan Kappen
il 20 Nov 2015
Jan
il 23 Nov 2015
You can accept one answer only. But you can vote for more answers and a comment is useful also.
Categorie
Scopri di più su Structures in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!