I have a cell array in MATLAB in the following format:
aa = {[1 2],[2 3],[1 2 3 4 5 6],[5],[1]}
Run Code Online (Sandbox Code Playgroud)
Is it possible to create a diagram in this style (i.e. filling in a block colour for each time a number shows up)?
这是一个可能的解决方案,基于pcolor:
aa = {[1 2],[2 3],[1 2 3 4 5 6],[5],[1]};
n_rows = length(aa);
n_columns = max(cell2mat(aa));
m = zeros(n_rows + 1, n_columns + 1);
row = n_rows;
for i=1:n_rows
m(row, aa{i}) = 1;
row = row - 1;
end
colormap([1 1 1; 1 0.5 0]);
pcolor(m);
Run Code Online (Sandbox Code Playgroud)
它产生以下结果: