How do I plot the data as patches rather than vertices in a grid or a mesh?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have been trying to visualize a set of stochastic data like the matrix below:
1 1 1 2 2 3 3;
1 1 1 2 2 3 3;
1 1 1 1 2 2 3;
1 1 1 1 2 2 3;
1 1 1 1 2 2 3;
I want to create something similar to a chess board, with 1 being blue, 2 being yellow and 3 being red (see the attached figure).
I have tried contourf and surf, but they all put data on the vertices of the lattices, so if the shading function is faceted, it will give
And if the shading is interp, it will be
The boundaries between ones, twos and threes is an artificial transition at the blank area where no data exist.
I then tried adding an additional row and column, or, as Youssef KHMOU suggested, using the kron function. Both ways gave the right lattice pattern, but then I had to manually adjust the position of the ticks to produce the first graph, which is what I need.
Is there a better way to do this?
0 Commenti
Risposte (3)
Star Strider
il 8 Mag 2014
A = 1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 2 2 1 1 1 2;
2 2 2 2 3 3 2;
2 2 3 3 3 3 3];
figure(1)
pcolor(A)
axis equal
colormap(gray)
2 Commenti
Star Strider
il 9 Mag 2014
This may be what you want:
A = [1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 2 2 1 1 1 2;
2 2 2 2 3 3 2;
2 2 3 3 3 3 3];
x = [0:6]+0.5;
y = [0:4]+0.5;
figure(1)
image(x, y, A)
axis equal tight
colormap(gray(3))
grid on
h = get(gca)
set(gca, 'YTick', 0:5, 'GridLineStyle','-')
produces:
Youssef Khmou
il 8 Mag 2014
Tensor product can be efficient in representing each number with different color, but try this way i think it is convenient to your description :
M=ones(4,1)*(1:4)
surface(M)
3 Commenti
Youssef Khmou
il 8 Mag 2014
it was only a way to create a matrix similar to that you posted, so surface is not working?
Kun
il 8 Mag 2014
Modificato: Kun
il 8 Mag 2014
2 Commenti
Youssef Khmou
il 8 Mag 2014
try :
M=ones(4,1)*(1:4);
B=kron(M,ones(3));
figure; surface(B);
% shading interp
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!