1

Is it posible to set up a function in matlab that returns an interval of numbers into a specified letter, i can only make 1=A, 2=B and so on... I want a function that can make numbers between 0-10.5=B, 9.5-20.5=X, all the way up till 300 with a new letter each time, is that even possible or do i just have to make the long manual way?

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
Mikkel Astrup
  • 405
  • 6
  • 18

2 Answers2

1

I would write a function as:

function out = mapNumbers(num)
buckets = [10.5:10:300]; % Create array of the form 10.5 20.5 30.5 ....290.5 
letters = [B X ....]; % You will have to type all letters, there is no way out
idx = find(buckets > num, 1); % find 1st bucket edge > num
out = letters[idx]; % This is the letter the number corresponds to 
end

You can tweak with the buckets and find to make it work for your case. Make sure that buckets > num really works the way you define your number to be in a particular bucket (> and >= stuff).

Some Guy
  • 1,787
  • 11
  • 15
0

Unless there's a nice pattern for your numbers, I believe you're going to have to use a switch and hardcode it all in. Saying that, you may be able to have a case for a relatively large range, if there are chunks of your number range which do follow the same pattern.

Lui
  • 403
  • 2
  • 15