UKBouldering.com

Scilab / Matlab Geekery Needed (Read 2737 times)

Paul B

Offline
  • *****
  • forum hero
  • Posts: 9631
  • Karma: +264/-4
Scilab / Matlab Geekery Needed
October 14, 2015, 04:24:41 pm
This will be of little interest to the vast majority of UKB users I'm sure, however, I'm trying to code something (supposedly to make my life easier) and I'm currently limited to SciLab (having learnt Matlab at University).

What I'm trying to do is fairly simple; linearly interpolate between values and return another value, e.g:

  x     y
300 1000
200 850
100 600

Return y value for x = 150.

I've realised that all of the interpolate functions I've found relate to data fitting and thus aren't really working for this. Any clues?
 :tumble:

around

Offline
  • *
  • newbie
  • Posts: 4
  • Karma: +0/-0
#1 Re: Scilab / Matlab Geekery Needed
October 14, 2015, 04:36:24 pm
https://help.scilab.org/doc/5.5.2/en_US/interpln.html seems to be what you want.

Something like interpln([100 200 300; 600 850 1000], [150]).

tomtom

Offline
  • *****
  • forum hero
  • Posts: 20293
  • Karma: +642/-11
#2 Re: Scilab / Matlab Geekery Needed
October 14, 2015, 04:42:06 pm
Could you fit a regression line and use the eqtn?

cjsheps

Offline
  • ***
  • obsessive maniac
  • Posts: 314
  • Karma: +8/-0
  • The Hero Gotham Deserves.
#3 Re: Scilab / Matlab Geekery Needed
October 14, 2015, 05:31:06 pm
Create two arrays x and y, containing your values. Then use the command:

[polyCoeffs, s] = polyfit(x,y,1);

m=polyCoeffs(1)
c=polyCoeffs(2)  <----I think this is the notation

x0=(the value of x you want)
y0=m*x0 + c <----equation of a straight line

Hope this helps.

Paul B

Offline
  • *****
  • forum hero
  • Posts: 9631
  • Karma: +264/-4
#4 Re: Scilab / Matlab Geekery Needed
October 14, 2015, 06:46:47 pm
Quote from: tomtom link=topic=26f423.msg502633#msg502633 date=1444837326
Could you fit a regression line and use the eqtn?

No. You'd need to do that between each data point due to what it represents.

It was the interpln function I've used that isn't returning the desired result. I've manually input the value from the excel sheet that does the same thing and its pointing towards the function being used improperly by my.

Paul B

Offline
  • *****
  • forum hero
  • Posts: 9631
  • Karma: +264/-4
#5 Re: Scilab / Matlab Geekery Needed
October 15, 2015, 01:49:03 pm
https://help.scilab.org/doc/5.5.2/en_US/interpln.html seems to be what you want.

Something like interpln([100 200 300; 600 850 1000], [150]).

The above is the function that didn't work as I'd expected in the OP.

I found interp1(x,y,x1) worked just fine and with a fresh pair of eyes this morning the code is up and running. Scilab is worth a look for anyone who used Matlab etc. during University and doesn't have/want a friend in prison etc.

JamieG

Online
  • *****
  • forum hero
  • Posts: 1286
  • Karma: +80/-0
#6 Re: Scilab / Matlab Geekery Needed
October 15, 2015, 04:52:07 pm
I use the interp1 function a lot in Matlab and you can change the method by which it interpolates. i.e. you can ask it to use 'linear','cubic','spline' etc depending on what you want it to do. I don't know if it implemented in Scilab.

Paul B

Offline
  • *****
  • forum hero
  • Posts: 9631
  • Karma: +264/-4
#7 Scilab / Matlab Geekery Needed
October 15, 2015, 08:23:52 pm
It is!

Given my current role it's just hard to make code auditable in general as required. Comments help a little.

Nonetheless, I'm getting fed up of clunky spreadsheets that work flawlessly as code not to mention the ease of plotting large data sets.

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal