String value and relate with number.
    6 ビュー (過去 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 件のコメント
採用された回答
  rifat
      
 2014 年 5 月 26 日
        A=21;B=12;C=8;D=7;
W=['DABCD'];
Z=W(1:3);
string=[Z(1) '*' Z(2) '*' Z(3)];
eval(string)
その他の回答 (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 で Characters and Strings についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


