reorder on a plot
16 次查看(过去 30 天)
显示 更早的评论
vComplDire contains randomly on each cell one of these 4 directions:
DownRight; DownLeft; UpRight; UpLeft. (these are simply strings).
vComplDire is loaded by this for loop:
for i = 1:numel(vInterv)
if vbHori(i)
vComplDire{i} = 'Up';
else
vComplDire{i} = 'Down';
end
if vbVert(i)
vComplDire{i} = [vComplDire{i} 'Right'];
else
vComplDire{i} = [vComplDire{i} 'Left'];
end
end
boxplot(vInterv, vComplDire);
Boxplotting I get the graphic that I show on the attached pic.
I want to reorder the boxes on the graph like this:
1st DownLeft; 2nd DownRight; 3rd UpLeft; 4th UpRight.
I tried with "reorderlevels", "getlevels", etc... but no success.
0 个评论
采纳的回答
Voss
2022-1-12
% Generate random data. In order to be able to distinguish the boxes, make
% UpRight have mean 0, DownRight have mean 1, DownLeft have mean 2, and UpLeft have mean 3.
vInterv = randn(100,4)+[0 1 2 3];
vbHori = [true false false true];
vbVert = [true true false false];
vComplDire = cell(1,4);
for i = 1:4
if vbHori(i)
vComplDire{i} = 'Up';
else
vComplDire{i} = 'Down';
end
if vbVert(i)
vComplDire{i} = [vComplDire{i} 'Right'];
else
vComplDire{i} = [vComplDire{i} 'Left'];
end
end
vComplDire
[~,idx] = ismember({'DownLeft','DownRight','UpLeft','UpRight'},vComplDire)
boxplot(vInterv(:,idx), vComplDire(idx));
4 个评论
Voss
2022-1-13
When i == 5 you will get an error in the for loop because vbHori only has 4 elements.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!