# Interpolate values to the nearest 0.25 and create indices for these values

3 views (last 30 days)
Macie Smith on 1 Jul 2020
Commented: Macie Smith on 1 Jul 2020
I have multiple matrices that I am trying to combine, so I need to tranform data into positive integers.
Code to create the example 2D matrix:
Cap=10;
x=linspace(1,Cap,Cap)';
F = 10;
p = 7;
b = [(1./(1+(exp(p-x))))];
SO = [0.75];
Rsb = [F*b*SO];
Which I make into a 3D matrix such as rp1 below:
rp1 = RNO;
rp1(:,:,2) = R0;
This matrix contains a lot of zeros and values with several decimal places.
I am trying to use a linear interpolation (rather than actually rounding) to get these decimals to the nearest 0.25. I have no idea how to do this!
I then would like to take these values, to the nearest 0.25 (and all the zeros!) and create an index for these values -- so I can convert between the indices and the actual values, and so my matrices consist of all positive integers so I can add them. To do this, I believe I would need some number of categories that these values fall into. Values across matrices run from 0 to 8, so I believe once I have them to the nearest 0.25 I'll have 32 categories. After this, I'm at a total loss!
I greatly welcome and appreciate any and all help!
Macie Smith on 1 Jul 2020
RNO would be fine too!
I can always just interpolate/create indices for the core values (core values from 2D matrices such as RNO and R0) and manually create the 3D matrices the way I did for rp1.

Matt J on 1 Jul 2020
vals=linspace(0,8,32+1);
rp1(:)=interp1(vals,vals, rp1(:),'nearest')
Macie Smith on 1 Jul 2020
THANK YOU SO MUCH!
I was able to jump off this to figure out the array indices.