From: John D'Errico on
"Nadine Cooper" <f9071770(a)bournemouth.ac.uk> wrote in message <hqf51s$kno$1(a)fred.mathworks.com>...
> "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <hqf2me$duq$1(a)fred.mathworks.com>...
> > Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <66262580-4f21-42b0-b8ad-4e2774616da8(a)b33g2000yqc.googlegroups.com>...
>
> > > Search among John D'Errico's contributions on the FEX.
> >
> > (Actually, I DID write a tricontour function some time
> > ago, but Darren wrote/posted a better version than I
> > had, before I had time to post mine anyway.)
> >
> > John
>
>
> Hi John,
>
> I did search through your contributions on the file exchange, and found your gridfit demo; I've started to play around with that though I'll now try out the tricontour files as well. Which do you reckon is more suitable? I thought gridfit did pretty much what I need - fits a surface to a scatter plot (which is inherently the data type I've got)
>
> Though I could be wrong!
>
> Forgive me, I'm very new to Matlab and there's just so much information being thrown around!
>
> However, I thank you sincerely for replying and helping me out :)

It depends on your goals. Gridfit will produce a smooth
surface from your data. If you did not like what the
'cubic' option for griddata did, then you may not want
what gridfit will do here.

It sounds like you wanted the surface to more carefully
emulate the character of this sparse set of data, without
the interpolation producing extrema into the function that
did not exist in the data. If so, then you will find tricontour
more appropriate.

HTH,
John
From: Nadine Cooper on

> It depends on your goals. Gridfit will produce a smooth
> surface from your data. If you did not like what the
> 'cubic' option for griddata did, then you may not want
> what gridfit will do here.
>
> It sounds like you wanted the surface to more carefully
> emulate the character of this sparse set of data, without
> the interpolation producing extrema into the function that
> did not exist in the data. If so, then you will find tricontour
> more appropriate.
>
> HTH,
> John

Yes, you're right, gridfit - although extremely brilliant - didn't produce what I wanted.

Tricontour is proving altogether more difficult -

Please don't flame me, but I think it's due to my not understanding the principles behind it. I've been playing around with it, and going off of the examples, I think this is what I need to do:

x = [50 67 110 140 162 190 235 262]'
y = [81 209 135 78 78 135 209 81]'
z = [254 41 249 80 83 230 40 210]'
v = 255;
rangeY = min(y):5:max(y);
rangeX = min(x):5:max(x);
[xx,yy] = meshgrid(rangeX,rangeY);
zz = griddata(x,y,z,xx,yy);
p = [xx(:),yy(:)];
t = delaunayn(p)
tricontour(p,t,zz(:),v);

I think it's the griddata part - though I don't quite understand how to get zz without using it.

But it's producing a contour of griddata, not my initial x,y point coordinates. Extrema are still being produced that I don't want - ie, one massive peak that should denote two separate peaks.

I'm so sorry, I'm not understanding. The help tricontour gives very sparse examples, but without explanation of the reasons WHY things are being done as they're done, so I'm not grasping it. My own fault for being dense, I know!

I know it's not even your FEX file; so this may be a huge ask, but are you able to explain things in layman's terms?
From: John D'Errico on
"Nadine Cooper" <f9071770(a)bournemouth.ac.uk> wrote in message <hqfaal$b3e$1(a)fred.mathworks.com>...
>
> > It depends on your goals. Gridfit will produce a smooth
> > surface from your data. If you did not like what the
> > 'cubic' option for griddata did, then you may not want
> > what gridfit will do here.
> >
> > It sounds like you wanted the surface to more carefully
> > emulate the character of this sparse set of data, without
> > the interpolation producing extrema into the function that
> > did not exist in the data. If so, then you will find tricontour
> > more appropriate.
> >
> > HTH,
> > John
>
> Yes, you're right, gridfit - although extremely brilliant - didn't produce what I wanted.
>
> Tricontour is proving altogether more difficult -
>
> Please don't flame me, but I think it's due to my not understanding the principles behind it. I've been playing around with it, and going off of the examples, I think this is what I need to do:
>
> x = [50 67 110 140 162 190 235 262]'
> y = [81 209 135 78 78 135 209 81]'
> z = [254 41 249 80 83 230 40 210]'
> v = 255;
> rangeY = min(y):5:max(y);
> rangeX = min(x):5:max(x);
> [xx,yy] = meshgrid(rangeX,rangeY);
> zz = griddata(x,y,z,xx,yy);
> p = [xx(:),yy(:)];
> t = delaunayn(p)
> tricontour(p,t,zz(:),v);
>
> I think it's the griddata part - though I don't quite understand how to get zz without using it.
>

You never need to use griddata at all. This SHOULD
work:

tri = delaunay(x,y);
tricontour([x,y],tri,z,50)

I'm surprised that there is a hole in it on this set of
data. Further exploration shows the contour plot is
not even correct.

Sigh.

Send me an e-mail, and I'll reply with working code
for your use.

John
From: Bruno Luong on
"Nadine Cooper" <nadine.beasley(a)hotmail.co.uk> wrote in message <hqevu9$29q$1(a)fred.mathworks.com>...
> Hi all,
>
> I'm working a project that will map (contour) pressure points on a cushion.
>
> I've got 8 sensors placed to map pressure points under specific parts of the body.
>
> Here's what it looks like: x and y correlate to the dimensions of the cushion and where sensors are placed
>
> x = [50 67 110 140 162 190 235 262]'
> y = [81 209 135 78 78 135 209 81]'
> plot(x,y,'.')
>
> The 'dots' show the sensor positions on the cushion
>
> What I'm trying to do is create a contour map to show elevations in pressure at EACH point marked above
>
> The following z values denote the binary readings from the sensors
>
> z = [254 41 249 80 83 230 40 210]'
>
>
> Here's what I'm doing at the moment:
>
> tri = delaunay(x,y)
> trisurf(tri,x,y,z)
> rangeY = min(y):5:max(y);
> rangeX = min(x):5:max(x);
> [X,Y] = meshgrid(rangeX,rangeY);
> Z = griddata(x,y,z,X,Y,'cubic')
> surf(X,Y,Z)
>
> rangeZ = min(z):5:max(z);
> contour(X,Y,Z,rangeZ)
>
> However, this isn't exactly what I want, and I'm sure it's due to my lack of calculations. I want a peak (or trough) for every sensor position, and what I'm getting so far is just an overall view of where pressure is high (255) and where it's low (10)
>

I just play with your data and I rather like griddata/contour plot. I'm not sure what you meant by " I want a peak for every sensor position", and can't see how the raw triangular mesh contour can render *peaks*?

But if you want to have a Gaussian peak centered at the sensor positions and such that the surface interpolates the data, you could try this method:

x = [50 67 110 140 162 190 235 262]';
y = [81 209 135 78 78 135 209 81]';
z = [254 41 249 80 83 230 40 210]';
%
rangeY = linspace(0,300,65);
rangeX = linspace(0,300,65);
[X,Y] = meshgrid(rangeX,rangeY);
%
GaussianWidth = 25; % adjust at your will, smaller value -> sharp peak
% Find the amplitude of the Peaks
n = length(x);
M = zeros(n);
for k=1:n
Mk = exp(-((x(:)-x(k)).^2 + (y(:)-y(k)).^2) / (2*GaussianWidth^2));
M(:,k) = Mk;
end
A = M\z(:);

% Reconstruct the surface with peaks from the amplitude
zfit = 0;
for k=1:n
Gk = exp(-((X-x(k)).^2 + (Y-y(k)).^2) / (2*GaussianWidth^2));
zfit = zfit + A(k)*Gk;
end

% Plot
surfc(rangeX,rangeY,zfit)

% Bruno
From: Nadine Cooper on
Bruno,


Thank you, that's actually quite helpful -

So I've been messing around with your code - and after having calibrated my system, I'm now calculating to determine pressure of the sensors in mmHg.

However, as a result, if an item in the initial z (sensor reading) field is a 0, then I get this:

??? Error using ==> contourc
Input matrix contains no finite values - unable to calculate contours

Error in ==> contours at 57
CS=contourc(varargin{numarg_for_call});

Error in ==> contour3 at 87
[c,msg] = contours(args{1:nin});

Error in ==> surfc at 62
[cc,hh] = contour3(cax,x,y,z); %#ok

Error in ==> FSR_GAUSSIAN at 45
surfc(rangeX,rangeY,zfit)

Now, interestingly, before I changed things around to contour the calibrated data, the system accepted 0s without error

Now it doesn't - I don't quite understand. I'm assuming because of issues such as division by 0 and all that, so NaN values are being returned?

Any ideas how to fix it? Or is it not possible?


Here's the code now:

x = [50 67 110 140 162 190 235 262]';
y = [81 209 135 78 78 135 209 81]';
z = [0 255 10 120 120 3 246 2]';

% calibration
kg = [ 1 11 15 20 25 30 35 40 45 50 55 58]'
bin = [1 15 19 23 29 34 73 137 195 226 243 255]'
x1 = [1:1:255]'
W = interp1(bin, kg, x1)

%fitting calibration data to show weight to binary correlation
z2 = interp1(W,z)

%determine kg/m^2 -> mmHg
z2(1,1) = (((z2(1,1)*100)/0.0720)* 0.00750061505043)
z2(2,1) = (((z2(2,1)*100)/0.0720)* 0.00750061505043)
z2(3,1) = (((z2(3,1)*100)/0.0720)* 0.00750061505043)
z2(4,1) = (((z2(4,1)*100)/0.0720)* 0.00750061505043)
z2(5,1) = (((z2(5,1)*100)/0.0720)* 0.00750061505043)
z2(6,1) = (((z2(6,1)*100)/0.0720)* 0.00750061505043)
z2(7,1) = (((z2(7,1)*100)/0.0720)* 0.00750061505043)
z2(8,1) = (((z2(8,1)*100)/0.0720)* 0.00750061505043)

%
rangeY = linspace(0,300,65);
rangeX = linspace(0,300,65);
[X,Y] = meshgrid(rangeX,rangeY);
%
GaussianWidth = 15; % adjust at your will, smaller value -> sharp peak
% Find the amplitude of the Peaks
n = length(x);
M = zeros(n);
for k=1:n
Mk = exp(-((x(:)-x(k)).^2 + (y(:)-y(k)).^2) / (2*GaussianWidth^2));
M(:,k) = Mk;
end
A = M\z2(:);

% Reconstruct the surface with peaks from the amplitude
zfit = 0;
for k=1:n
Gk = exp(-((X-x(k)).^2 + (Y-y(k)).^2) / (2*GaussianWidth^2));
zfit = zfit + A(k)*Gk;
end

% Plot
surfc(rangeX,rangeY,zfit)
title ('Pressure Distribution')
zlabel ('Pressure mmHg')
xlabel ('mm')
ylabel ('mm')
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: blood simscape
Next: neural network outputs