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

3 visualizaciones (últimos 30 días)
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];
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!
  3 comentarios
Macie Smith
Macie Smith el 1 de Jul. de 2020
the rp1 matrix if possible!
and yes, 33 thank you
Macie Smith
Macie Smith el 1 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 1 de Jul. de 2020
vals=linspace(0,8,32+1);
rp1(:)=interp1(vals,vals, rp1(:),'nearest')

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by