String value and relate with number.
1 次查看(过去 30 天)
显示 更早的评论
lets say i have A=21,B=12,C=8,D=7 and Matrix with string value W=['DABCD'], and now lets say when i write: Z=W(1:3) which will give result DAB string from W. and i want that to be multiplication of D*A*B which is equal to 2016.
0 个评论
采纳的回答
更多回答(1 个)
Cedric
2014-5-26
编辑:Cedric
2014-5-26
Here is one solution. Assuming
W = ['DABCD'] ;
Define
values = [21, 12, 8, 7] ; % or values = [A, B, C, D] ;
Z = @(id) prod( values(W(id)-64) ) ; % Function lookup/prod.
Then you can use Z as a function, which works using the same syntax as the indexing used in your question statement:
>> Z(1:3)
ans =
1764
Note that 7*21*12 = 1764 and not 2016.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!