How can I dynamically create a cell array of cell arrays?
Show older comments
I am iterating through a cell to match the id row from one cell array 1 to the id row from another cell array 2. I am trying to dynamically retrieve all of the values from cell array 1 when the value from cell array 2 matches.
Not sure how to create dynamic cell structures as shown below with my 'housesPerCluster' variable. Inside my if statement, I want it to add the value to a cell when it finds a matching iterClusterId.
I am stuck on the syntax for how to create a new cell 'housesPerCluster' with cells inside of it that align with the ClusterId. So I want all of the house Ids that match clusterId 1, 2, and so on, up to the number of clusters (numClusters). My code to loop looks like this:
housesPerCluster = cell{1,numClusters};
for iterClusterId = 1:numClusters
for iterRow = 1:houseNum
if idAndCluster{1,2}{iterRow,1} == iterClusterId
housesPerCluster{iterClusterId}{end+1} = idAndCluster{1,1}{iterRow,1};
end
end
end
Thanks
2 Comments
john cadigan
on 23 Oct 2018
madhan ravi
on 23 Oct 2018
Glad that you found out but do read the link below
Answers (1)
madhan ravi
on 23 Oct 2018
0 votes
Categories
Find more on Multidimensional Arrays 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!