How can I recover data stored in cells ?
1 view (last 30 days)
Show older comments
Constantine Papakonstantinou
on 31 Jan 2016
Commented: Constantine Papakonstantinou
on 31 Jan 2016
Hello, I have been doing some work in Matlab and I am unfamiliar with using cells. I would like to know how to access data which I have stored in cells. I have tried cell2mat(), but I get the following error:
Error using cell2mat (line 52) CELL2MAT does not support cell arrays containing cell arrays or objects.
if true
% cx = centerxFinal;
% cy = centeryFinal;
% rad = radiusFinal;
%
% columns = size(centeryFinal,2);
% rows = size(centeryFinal,1);
%
% for i = 1:columns-1
% for j = 1:rows
% for k = 1:rows
% if ((cy(j,i+1) ~= 0 && cy(k,i) ~= 0) && (cx(j,i+1) ~= 0 && cx(k,i) ~= 0))
% y_dist(j,i,k) = cy(j,i+1)-cy(k,i);
% xy_points{j,i,k} = {[centeryFinal(j,i+1),centeryFinal(k,i)],[centerxFinal(j,i+1),centerxFinal(k,i)]};
% x_dist(j,i,k) = cx(j,i+1)-cx(k,i);
% else
% xy_points{j,i,k} = 0;
% end
% end
% end
% end
% for i = 1:columns-1
% for j = 1:rows
% for k = 1:size(xy_points,3)
% if y_dist(j,i,k) > 50 || y_dist(j,i,k) < -50
% xy_points{j,i,k} =0;
% end
% if x_dist(j,i,k) <= 0 || x_dist(j,i,k) < 400
% xy_points{j,i,k} =0;
% end
% end
% end
% end
end
The result of this script is a three dimensional cell containing cells which cointain pairs of points.
Is there a function or algorithmic process I can use to retrieve the data points that have survived the filtering process?
0 Comments
Accepted Answer
Image Analyst
on 31 Jan 2016
To recover data stored in cells, you also use the braces again:
cellContents = xy_points{j,i,k};
I see no reason in your code to mess with cells at all. You don't have stuff of variable type or size. To make it even more confusing, it seems like the variable editor is saying you have cells inside of cells. How confusing is that?
See the FAQ for a good intuitive discussion of what cells are: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
3 Comments
Image Analyst
on 31 Jan 2016
I don't understand. For a location of (row, column), the distances to the other pixels in the next column is simply going to be sqrt(1), sqrt(2), sqrt(3), sqrt(4), etc. In general:
totalRows = 10
thisRow = 4;
% Find distance of element in thisRow to element in next column for all rows.
deltaY = -(thisRow - 1) : (totalRows - thisRow)
deltaX = 1; % It's just the next column over.
distances = sqrt(deltaX.^2 + deltaY.^2)
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks 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!