help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sliceomatic for Octave? Plotting "slices" of f(x, y, z)


From: lcocea
Subject: Re: Sliceomatic for Octave? Plotting "slices" of f(x, y, z)
Date: Sun, 6 Aug 2017 08:00:40 -0700 (PDT)

OK, reposting the two code sections w/o formatting, I hope this helps.

---- 
%
% Demo myScatter3d - Normal distribution
% f(x, y, z) = exp(-(x^2 + y^2 + z^2))
%

% Compute x, y, z, c
s = linspace(0, 1, 20);
m = length(s);
x = []; y = []; z = []; f = [];
ct = pi;  % arbitrary constant

for i = 1:m
    for j = 1:m
        for k = 1:m 
            x = [x, s(i)];
            y = [y, s(j)];
            z = [z, s(k)];
            f = [f, ct * exp(-(s(i)^2 + s(j)^2 + s(k)^2))];       
        end
    end
end

[result, errmsg] = myScatter3d(x, y, z, f, 4);
if (result != 1)
    disp(errmsg);
end
---- 

---- 
function [result, errmsg] = myScatter3d(xv, yv, zv, fv, n)

% Expecting the best
result = 1;
errmsg = "";

lx = length(xv);
ly = length(yv);
lz = length(zv);
lf = length(fv);

% n(slices) must be in 1..12
if !((n > 0) && (n <= 12))
    result = 0;
    errmsg = "Number of slices must be between 1 and 12";
    return;
end
nslices = n;

% Vectors x, y, z, c must have the same length
if !((lx = ly) && (ly = lz) && (lz = lf))
    result = 0;
    errmsg = "Vectors x, y, z, f must have the same length";
    return;
end
m = lx;

% Vector size must be >= 2
if (lx < 2)
    result = 0;
    errmsg = "Vector size must be at least 2";
    return;
end

% Get limits for vectors xv, yv, zv: must be > 0
xlimits = [min(xv), max(xv)];
ylimits = [min(yv), max(yv)];
zlimits = [min(zv), max(zv)];
if !((xlimits(1) < xlimits(2)) || (ylimits(1) < ylimits(2)) || (zlimits(1) <
zlimits(2)))
    result = 0;
    errmsg = "Vectors x, y, z must have different minimum and maximum
values";
    return;
end
flimits = [min(fv), max(fv)];

% Normalize fv: [flimits(1), flimits(2)] -> [0, 1];
delta = flimits(2) - flimits(1);
for i = 1:length(fv)
    fv(i) = (fv(i) - flimits(1)) / delta;
end
flimits = [min(fv), max(fv)];

%  Setup color palette
ncolours = 512;
colmap = rainbow(ncolours);

% Initialize x, y, z, c
slice = linspace(0, 1, nslices + 1);  % [0, 1]
x = {};
y = {};
z = {};
c = {};

% Compute x, y, z, c for scatter3
for i = 1:m
    for idx = 1:nslices
        if (slice(idx) <= fv(i)) && (fv(i) < slice(idx + 1))
            if length(x) < idx
                x{idx} = [];
                y{idx} = [];
                z{idx} = [];
                c{idx} = [];
            endif
            x{idx} = [x{idx}, xv(i)];
            y{idx} = [y{idx}, yv(i)];
            z{idx} = [z{idx}, zv(i)];
            c{idx} = [c{idx}, fv(i)];
        endif
    end
end

% Convert c -> palette colours
for i = 1:length(c)
    temp = [];
    for j = 1:length(c{i})
        temp = [temp; colmap(max(1, round(c{i}(j) * ncolours)), :)]; 
    end
    c{i} = temp;
end

% Scatter 3D plots
for i=1:nslices
    subplot(1, nslices, i);
    scatter3(x{i}', y{i}', z{i}', 512, c{i}, "filled");
    xlim(xlimits); ylim(ylimits); zlim(zlimits);
    xlabel('x'); ylabel('y'); zlabel('z'); 
end
---- 


On Sun, Aug 6, 2017 at 10:36 AM, lcocea &lt;lcocea@&gt; wrote:

> Doug, just wondering if the code is not shown in your reply because it was
> originally formatted as "raw text" and it was distributed to the mailing
> list in text-only mode. Can you see the screen shots? I posted the message
> at
> http://octave.1599824.n4.nabble.com/Sliceomatic-for-
> Octave-Plotting-quot-slices-quot-of-f-x-y-z-td4684342.html
> please open this link and let me know if this works for you. Thanks.
>
>
>
> --
> View this message in context: http://octave.1599824.n4.
> nabble.com/Sliceomatic-for-Octave-Plotting-slices-of-f-x-
> y-z-tp4684342p4684346.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@
> https://lists.gnu.org/mailman/listinfo/help-octave
>

Yes I can see that, and no it is not visible in Ubuntu chrome or Firefox,
or samsung android gmail or  samsung browser




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Sliceomatic-for-Octave-Plotting-slices-of-f-x-y-z-tp4684342p4684348.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]