如何在3D绘图中绘制具有不同颜色的单元格中的每个矩阵?

时间:2017-09-06 01:45:30

标签: matlab plot colors matlab-figure

考虑一个1x3小区library(dplyr) df <- tibble( year= c("1997", "1997","1997","1997","1997","1997","1998","1998"), season= c("W", "W","W","D","D","D","W","W"), result= c("Y", "Y","N","N","Y","N","N","N") ) df %>% mutate(result = recode(result, "Y" = 1L, "N" = 0L)) %>% group_by(year, season) %>% summarise(psit_freq = mean(result)) #> # A tibble: 3 x 3 #> # Groups: year [?] #> year season psit_freq #> <chr> <chr> <dbl> #> 1 1997 D 0.3333333 #> 2 1997 W 0.6666667 #> 3 1998 W 0.0000000

A

A = { [A1] [A2] [A3] } A = {[1 2 3; 4 5 6; 7 8 9] [6 5 4; 9 8 7] [1 1 1]} 的结构如下:

Ai

如何绘制所有这些点,以便我们为A1 = [ 1 2 3 %coordinate (x,y,z) of point 1 4 5 6 %coordinate (x,y,z) of point 2 7 8 9 ] %coordinate (x,y,z) of point 3 A2 = [ 6 5 4 %coordinate (x,y,z) of point 4 9 8 7 ] %coordinate (x,y,z) of point 5 A3 = [ 1 1 1 ] %coordinate (x,y,z) of point 6 的所有点使用一种颜色,为A1的所有点使用另一种颜色,为{{1}的所有点使用其他颜色}}?

一般来说,如果我们有一个1xn的小区,即A2,怎么办呢?

1 个答案:

答案 0 :(得分:1)

连接单元格数组update testplans set tc_name=regex_replace('.*/','',tc_path); vertically内的所有矩阵。使用jetany other colormap为不同的矩阵生成不同的颜色。找到A内每个矩阵中的点数,以确定每种颜色重复的次数。相应地生成每种颜色的副本数量,最后使用scatter3绘制这些点。

A

对于给定的newA = vertcat(A{:}); %Concatenating all matrices inside A vertically colours = jet(numel(A)); %Generating colours to be used colourtimes = cellfun(@(x) size(x,1),A); %Determining num of times each colour wil be used colourind = zeros(size(newA,1),1); %Zero matrix with length equals num of points colourind([1 cumsum(colourtimes(1:end-1))+1]) = 1; colourind = cumsum(colourind); %Linear indices of colours for newA scatter3(newA(:,1), newA(:,2), newA(:,3),[], colours(colourind,:),'filled'); ,上面的代码产生了这个结果:

output