Rescale values based on a particular value

Hi,
I have a .csv file with ~200k values. I want to rescale the values to range -1 to +1. I know the rescale function can do this.
However, what I want to do is, I want the scaling to happen based on the max and min range that I provide and not the max and min values in the file itself. To give an example: the file contains values ranging from 2500-2800. I want to rescale it from -1 to +1 but -1 should correspond to 2300 and +1 should correspond to 3000.
How can I do it? I don't think rescale function provides this functionality. Is there any function for it? I have attached my file.
Thanks, Gagan

 採用された回答

Simon Chan
Simon Chan 2022 年 3 月 13 日

1 投票

Try the following:
data = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/925044/w3.csv');
rescale_data = rescale(data,-1,1,'InputMin',2300,'InputMax',3000);
subplot(2,1,1);
plot(data);
ylim([2300 3000]);
subplot(2,1,2);
plot(rescale_data);

5 件のコメント

Giggs B.
Giggs B. 2022 年 3 月 13 日
Thanks! But I have two doubts, if you can clarify. If I don't rescale the data in the file, I can't hear anything. I can only hear if I rescale it to smaller range such as -1 to 1 or 0 to 1, etc.
First doubt is, why can't I hear any sound if I don't do any scaling?
Second: Is there any advantage of choosing one range over the other? For example if I chose -1 to 1 over 0 to 1?
Simon Chan
Simon Chan 2022 年 3 月 13 日
I am sorry I am not an expert on audio signal.
I guess it is kind of resolution issue where rescale helps to improve it. (Guess only!)
You may refer to other websites (such as the following) for detail explanation or open another question to see someone can give you a better answer.
Giggs B.
Giggs B. 2022 年 3 月 13 日
Thank you! I'll check there.
Image Analyst
Image Analyst 2022 年 3 月 13 日
Maybe try soundsc() which scales audio so you can hear it.
Giggs B.
Giggs B. 2022 年 3 月 14 日
Hi, I think soundsc() does the samething what "rescale + sound" functions together do.
However, rescale also provides the flexibiity of setting 'InputMin' and 'InputMax' values which soundsc() does not provide.

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2022 年 3 月 13 日

コメント済み:

2022 年 3 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by