I want to create a bar3 plot for the contribution of two parameters as like in figure

3 次查看(过去 30 天)
I already obtained the correct form of the plot but magnitude and distance values are not in true position. As can bee seen from the figure, magnitude values in left figure are not in the same position with the right figure as well distance values. How to overcome from this problem? I already tried to change it in browser but it will not worth it because I have a lot of data that I need to obtain this plot. As an example, in second figure I shared the contribution of the two parameters in table.
and here is what I did in matlab:
bar3(B(3:end,3:end))
set(gca,'XTickLabel',B(2,3:end))
set(gca,'YTickLabel',B(3:end,2))
  5 个评论
bus gogen
bus gogen 2022-8-10
I am wondering that is there a way to obtain the contribution value for 5.05 and 45 as 0.0028 in bar3 or I don't know which plot should I use? Because as you see from the unreadible image(sorry for that but this is the best resolution), the third value is around five at the magnitude axes but in my plot 5 is at the end of that axis. This not correct.

请先登录,再进行评论。

回答(2 个)

Cris LaPierre
Cris LaPierre 2022-8-10
I see what you are saying. Magnitude corresponds to your Y axis, which corresponds to the rows of B. In the file, they increase from 4.55 to 9.45, but in your bar chart, they go from 4.55 to 5.05. This is because the labels are belng added to the tick locations MATLAB automatically selected. To get the output you want, you need to first set the tick locations.
However, this is unnecessary here. Use the following syntax to get the correct values on Y. Then you just need to update X ticks.
load B.mat
X = B(2,3:end); % columns of matrix
Y = B(3:end,2); % Rows of matrix
data = B(3:end,3:end);
bar3(Y,data)
xticks(X) % Just to be safe, set the tick locations to be what you are expecting them to be
xticklabels(X)

dpb
dpb 2022-8-10
OK...had a few minutes -- try
Z=B(3:end,3:end); % save the data portion of the overall arrray; MATLAB will, I think) just create reference
Y=B(3:end,2); % get the coordinate data
X=B(2,3:end);
hB3=(Y,Z);
ylim([Y(1) Y(end)]) % show only range of Y
xticks((1:2:numel(X)))
xticklabels(X(1:2:end))
hAx=gca;
hAx.XAxis.TickLabelRotation=-55;
hAx.FontSize=8;
produced
which sets the X and Y axis tick labels to the actual ranges.
You can't see the particular values you're mentioning because the preceding rows occlude the smaller middle rows at that orientation; if you rotate so can "look" between those row, you'll be able to see the values are there.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by