Sorting elements according to an array

1 次查看(过去 30 天)
I will try my best to phrase this question, hope it makes sense
I have 2 arrays, DATA which has useful data and SCALE which has the scale where I am fitting the data to.
DATA has numbers from 1-100 in random order, and SCALE has distinct intervals of tens from 1-100, i.e. 1,10,20,30...90,100
My goal is the write a code which clumps the elements from DATA to SCALE to do calulations such as SCALE-DATA (for example, 36 is the DATA element, the SCALE element should be 40 and it would be 40-36)
example - 7 will be rounded up to 10, and 23 will be rounded down to 20.
I understand the commands ciel and floor, however I am not sure what is the most efficient way to match the rounded data to the scale?

采纳的回答

Star Strider
Star Strider 2020-5-28
I am not certain what you want.
Try this:
DATA = randi([1 100], 25, 1); % Create DATA
SCALE = 10*round(DATA/10).*(DATA>=10) + 10*round(DATA/10).*(DATA<10);
Out = [DATA, SCALE];
.
  10 个评论
Hans123
Hans123 2020-5-29
Thank you for your time, I really appreciate it. I can tinker around with the helpful lines you have given me. I am glad to hear from you during these uncertain times. As always, thank you for the help Star Strider. Always a blessing to have you in this forum!
Star Strider
Star Strider 2020-5-29
As always, my pleasure!
Thank you very much for your compliments and sentiments!

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by