Dear MatLab users,
I'm trying to plot some data but I'm having some problems and I don't know which function is the most appropriate. What I need to do is the same as the chart below built on excel.
I have a vector of results, A, which is 360x1; a vector D which is 40x1, and a vector M which is 9x1 (note that 40*9=360). The vector A is built such that the first 40 elements refer to the first value of the M vector, and to the 40 elements of the vector D. The elements 41 to 80 refer to the second value of the M vector, and so on. In other words, the plane grid is defined by the vectors D and M, which are the x,y "coordinates" of the 360 values of the vector A.
How can I plot these values in MatLab? I searched a bit and I tried to use functions such as bar3 and hist3, but I failed.
% A is known from previous analyses
D = linspace(2.5 , 197.5 , 40 )';
M = linspace(4.75, 8.75, 9)' ;
% hist3( ?)
% bar3(?)
Another question similar to this one is to divide every parallelepiped in 6 parts (hence, a 2160=40*9*6 result vector), which correspond to a 6x1 vector of predefined values. The final result should look like the screen_2 attached. I assume the code to be similar to the one of the first question, but again, not sure how to do it.
Thank you

 Réponse acceptée

M.Many
M.Many le 28 Nov 2020
Hi,
you can try this
%load A
D = linspace(2.5 , 197.5 , 9 )';
M = linspace(4.75, 8.75, 9)';
bar3(reshape(A,40,9))
set(gca,'XTickLabel',M)
set(gca,'YTickLabel',D)
This is the closest I could get to the solution, hope it helps

4 commentaires

Gianluca Regina
Gianluca Regina le 29 Nov 2020
Modifié(e) : Gianluca Regina le 29 Nov 2020
Thanks for the help, your code does replicate the correct representation of the values (I was missing the reshape part) and it allowed to understand the true nature of the problem, the axis labeling. The true ticks are the 1,2,3..8,9 and 0,10,20,30,40,50, and the issue is that I need the labeling of these ticks as the values of my vectors M and D (for M all 9 should be possible, for D it depends on the size of the plot).
Sadly, in your code the xticklabel are not clear to read and the yticklabels are not where I want, though I can modify some of these things manually. In fact, I played a lot in the axis properties of the figure, and some things can be adjusted from there.
Is there a way to adjust the xticklabels and yticklabels within the code as I want?
Also, is there a way to make the 3d box bigger such that the xticklabes, as they are now with your code, will be more clear to read? EDIT: I added the view command and somehow solved the problem. So the Yticklabels is the only issue remaining I think.
M.Many
M.Many le 29 Nov 2020
Modifié(e) : M.Many le 29 Nov 2020
Hey, I think this is what you are looking for. Unfortunately you have to set all the labels for each axis on your own, the bar3 function is very limited. I think there are some plotting functions developped by the community that are more powerful, you can have a look at fileexchange.
D = linspace(2.5 , 197.5 , 40 )';
M = linspace(4.75, 8.75, 9)';
bar3(reshape(A,40,9))
%Specify number of ticks for X and Y axis
NumYTicks = numel(D)+2; % +2 comes from the very first and very last ticks of the axis
NumXTicks = numel(M)+2;
% Set the limits of the plot, very important
set(gca,'XLim',[0,numel(M)+1])
set(gca,'YLim',[0,numel(D)+1])
% Set the number of ticks for each axis
xlim = get(gca,'XLim');
set(gca,'XTick',linspace(xlim(1),xlim(2),NumXTicks))
ylim = get(gca,'YLim');
set(gca,'YTick',linspace(ylim(1),ylim(2),NumYTicks))
%Set labels for each tick
set(gca,'XTickLabel',[0;M;2*M(end)-M(end-1)]) % Add the very first and very last values to the plot
set(gca,'YTickLabel',[0;D;2*D(end)-D(end-1)])
% Change aspect of the plot by changing values here
pbaspect([3 5 2]) % Set it to [1 1 1] if you want a cubic plot
Gianluca Regina
Gianluca Regina le 29 Nov 2020
Yes, that seems to work pretty well, though the bar3 function is indeed limited and some manual adjustments are necessary. Still, I have really good starting point now, thank you very much!
M.Many
M.Many le 29 Nov 2020
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by