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

6 ビュー (過去 30 日間)
Macie Smith
Macie Smith 2020 年 7 月 1 日
コメント済み: Macie Smith 2020 年 7 月 1 日
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 件のコメント
Macie Smith
Macie Smith 2020 年 7 月 1 日
the rp1 matrix if possible!
and yes, 33 thank you
Macie Smith
Macie Smith 2020 年 7 月 1 日
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
Matt J 2020 年 7 月 1 日
vals=linspace(0,8,32+1);
rp1(:)=interp1(vals,vals, rp1(:),'nearest')
  1 件のコメント
Macie Smith
Macie Smith 2020 年 7 月 1 日
THANK YOU SO MUCH!
I was able to jump off this to figure out the array indices.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by