在Matlab中将数字间隔返回为字母



是否可以在matlab中设置一个函数,将数字的间隔返回到指定的字母中,我只能使1=a,2=B等等。。。我想要一个函数,它可以使0-10.5=B,9.5-20.5=X之间的数字,一直到300,每次都有一个新的字母,这可能吗?

我会把一个函数写成:

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

你可以调整水桶,找到适合你的情况。确保buckets > num真正按照您将数字定义为特定桶(>和>=东西)的方式工作。

除非你的数字有一个很好的模式,否则我相信你必须使用switch并将其全部硬编码。也就是说,如果你的数字范围中有块遵循相同的模式,你可能可以在相对较大的范围内使用case

最新更新