MATLAB Answers

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

3 views (last 30 days)
Macie Smith
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:
F = 10;
p = 7;
b = [(1./(1+(exp(p-x))))];
SO = [0.75];
Rsb = [F*b*SO];
Rss = [0*x];
RNO = [Rss Rbb];
Which I make into a 3D matrix such as rp1 below:
rp1 = RNO;
R0 = [Rss Rss];
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
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.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 1 Jul 2020
rp1(:)=interp1(vals,vals, rp1(:),'nearest')

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!