Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How plot a 3-order tensor in MATLAB

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 here

like image 730
kevin2019 Avatar asked Jun 21 '26 12:06

kevin2019


1 Answers

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);

enter image description here

like image 88
jodag Avatar answered Jun 24 '26 09:06

jodag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!