Change the range of an array

6 ビュー (過去 30 日間)
Ahmed Abdulla
Ahmed Abdulla 2021 年 12 月 22 日
回答済み: Image Analyst 2021 年 12 月 22 日
i have a 50x50 matrix with a maximum value of 1000 and a minimum of 200. I am looking for a way to increase the minimum to 350 and scale up the values accordingly but keep the maximum 1000.
Any help is appreciated

回答 (3 件)

Rik
Rik 2021 年 12 月 22 日
Essentially your question is this:
Given an array A with values ranging between 200 and 1000
How to find p0 and p1 such that B has values between 350 and 1000 after performing
B=p0+p1*A;
I would suggest using polyfit or determining the values yourself. If you pick the two extreme values, that shouldn't be difficult.

Walter Roberson
Walter Roberson 2021 年 12 月 22 日
formula = @(M) (M - 200)/(1000-200) .* (1000-350) + 350
formula = function_handle with value:
@(M)(M-200)/(1000-200).*(1000-350)+350
syms M
formula(M)
ans = 
subs(formula(M), M, 200:100:1000)
ans = 
So you could use the function handle for numeric work, or you could use the more direct but less obvious linear transformation shown as the symbolic formula

Image Analyst
Image Analyst 2021 年 12 月 22 日
Simply use rescale():
scaledMatrix = rescale(originalMatrix, 350, max(originalMatrix(:)));

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by