Reputation: 147
a = zeros(100,100,100);
distance = [1,21,41,61,81];
for d = 1:5
for i=distance(d): distance(d)+19
for j=distance(d): distance(d)+19
for k=distance(d): distance(d)+19
a(i,j,k) = 1;
end
end
end
end
The tensor a
with size (100,100,100) and all element dominate the diagonal.
How to visulize a
it in MATLAB
with zero is white color and one is black color. I plot in MS office, this is what I want Expected image
For matrix case, we can visualize as follow
X = zeros(100,100);
distance = [1,21,41,61,81];
for d = 1:5
for i=distance(d): distance(d)+19
for j=distance(d): distance(d)+19
X(i,j) = 1;
end
end
end
imagesc(a)
im = imagesc(1-X)
colormap(gray(256))
And the image is 2D matrix visulize
How to do a similar way for tensor?
And how to visulize tensor with noise? like noise on matrix
Upvotes: 3
Views: 1902
Reputation: 1
I tried this with scatter3:
nonzeros = find(a);
[px,py,pz] = ind2sub(size(a),nonzeros);
scatter3(px,py,pz,'k','.');
Upvotes: 0
Reputation: 22244
You can get pretty close to the plot produced in MS Office using isosurface
and isocaps
. AFAIK MATLAB doesn't have any built-in way of producing oblique projections, but if you're okay with an orthographic projection the following may work for you.
color = [0.2,0.2,0.2];
p1 = patch(isosurface(a), 'FaceColor', color, 'EdgeColor', 'none');
p2 = patch(isocaps(a), 'FaceColor', color, 'EdgeColor', 'none');
camlight left
camlight
lighting gouraud
isonormals(a, p1);
grid on;
view(3);
camorbit(-40,0);
Upvotes: 4