Mikkel Astrup
Mikkel Astrup

Reputation: 415

Return number-interval to letters in Matlab

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?

Upvotes: 1

Views: 50

Answers (2)

Some Guy
Some Guy

Reputation: 1797

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).

Upvotes: 1

Lui
Lui

Reputation: 403

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.

Upvotes: 0

Related Questions