Updating a Property in an Array of Objects
Show older comments
I have a class called WorkOrder that contains of several properties. My program brings in data from a SQL database as a Matlab table to be used as property values.. Once the data is imported, I check the height of the table and instatiate that exact amount of WorkOrder objects in a an array. I would now like to update the each of WorkOrder.properties by using the following type of statement:
[WorkOrder(1,:,1).wonbr] = listData.WONbr{:,1};
The above code works fine if the SQL datatype is a character string. However it fails if the SQL datatype is numeric with the error message: Brace indexing is not supported for variables of this type. But if I change the indexing to parentheses as below, I receive the error: Error using tabular/dotParenReference Too many output arguments.
[WorkOrder(1,:,1).nid] = listData.nid(:,1);
I could use a for loop as below, but it is too slow when the number of WorkOrder objects is high.
for i = 1:height(listData)
WorkOrder(i).nid = listData.nid(i,1);
end
Is there a way to make the middle statement above work for numberic data?
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!