Calling properties on an array of objects
6 views (last 30 days)
Show older comments
Hello everyone,
I have an array with objects of a class I created myself: The array is called Users and the elements in this array are from type User, a class I wrote myself. I now want to update a property for every object in the array. Currently, I am solving this issue by using a for loop. However, I've tried to replace the loop with a vector operation like this:
Users(:).propertyName = operation(....)
I received the following error message:
Expected one output from a curly brace or dot indexing
expression, but there were 100 results.
Is there a way I could still solve my issue? Or will I have to stick with the for loop, which is pretty time-consuming?
Thanks in advance
0 Comments
Answers (1)
Walter Roberson
on 6 May 2016
[Users(:).propertyName] = operation(....)
If the operation does not have the same number of outputs as the number of entries in the array, then you might need
[Users(:).propertyName] = deal(operation(....))
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!