在matlab上将char转换为整数 [英] Converting char to integer at matlab
本文介绍了在matlab上将char转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
将字符串转换为matlab中的数字数组
Possible Duplicate:
convert string to number array in matlab
我有一个包含值'1' '2' '3'
char值的向量y,我想将其转换为相应的整数向量.如果我使用str2num
,它会给出49 50 51
一样的数字.我该怎么办?
I have a vector y including values '1' '2' '3'
char values and I want to convert it to a corresponding integer vector. If I used str2num
it gives 49 50 51
like numbers. How could I do it ?
推荐答案
y - '0'
利用数字的ASCII值是连续的这一事实,从每个向量元素中减去'0'
的ASCII值.
Subtracts the ASCII value for '0'
from each vector element, taking advantage of the fact that the ASCII values for digits are contiguous.
这篇关于在matlab上将char转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文