假設您有一些單元陣列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