Units help to plot

2 次查看(过去 30 天)
Nina Perf
Nina Perf 2021-9-20
编辑: Nina Perf 2021-9-22
I want to convert values in a table column to a range of -1 to 1 units.
My -1 value is -800
My 0 value is 300
My 1 value is 800
The column values go from 0 to 800.
How can I do this?
Thanks!
  1 个评论
the cyclist
the cyclist 2021-9-20
编辑:the cyclist 2021-9-20
x = [-800 300 800];
y = [-1 0 1];
figure
h = plot(x,y,'.:');
set(h,'MarkerSize',32)
Nina, an infinite number of curves can be drawn through the three points you have specified. None of them are linear (so it is not what I would think of as a simple "conversion".)
Do you have any additional information that would be helpful in what you are trying to do? As I have mentioned in another of your questions, please try to be complete in what you are asking for.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2021-9-21
values = randi([0 800], 1, 10)
values = 1×10
709 747 795 14 63 285 232 537 508 183
b = [-800 300 800];
mask = values < b(2);
scaled(mask) = (values(mask)-b(1))./(b(2)-b(1));
scaled(~mask) = (values(~mask)-b(2))./(b(3)-b(2));
scaled
scaled = 1×10
0.8180 0.8940 0.9900 0.7400 0.7845 0.9864 0.9382 0.4740 0.4160 0.8936

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by