假设您有一些单元阵列cellarray
,其中包含16个[pixel number, z value]
对。这两行成立了一个随机演示...
% Set up random cell array, with 1x2 arrays in each cell
% First number in each array is unique pixel number, second is z value
z = num2cell(randi(64,4,4));
cellarray = cell(4,4); for ii = 1:16; cellarray{ii} = [ii z{ii}]; end;
现在,我们想绘制这一点,所以它转换成16×2矩阵,其中每行是1x2的细胞之一:
% Use the colon (:) to make cell array one column, use cell2mat to convert to matrix
g = cell2mat(cellarray(:));
要从索引获取2D x和y坐标,可以使用ind2sub
。
[x, y] = ind2sub([4, 4], g(:,1)); % Change [4, 4] to the size of your image
现在你可以使用plot3
绘制这些,持有,如果要保留以前的情节(如图像):
hold on % to retain previous plot, like from imagesc
plot3(x, y, g(:,2), '.'); % Using the dot to specify points not a line
是在cellarray {N}唯一的第一要素? – Wolfie
是的,它们是独一无二的。 cellarray {1}的所有第一个元素都是1,cellarray {2}的所有第一个元素都是2,等等。感谢您的帮助! – Anonymous
但是你在上面说过,例如'cellarray {2} = [18 1928]'所以第一个元素是18,而不是2? – Wolfie