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.

 채택된 답변

rifat
rifat 2014년 5월 26일

0 개 추천

A=21;B=12;C=8;D=7;
W=['DABCD'];
Z=W(1:3);
string=[Z(1) '*' Z(2) '*' Z(3)];
eval(string)

댓글 수: 1

Akmyrat
Akmyrat 2014년 5월 26일
thanks a lot Rifat. Appreciate your cooperation.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Cedric
Cedric 2014년 5월 26일
편집: Cedric 2014년 5월 26일

1 개 추천

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.

댓글 수: 1

Akmyrat
Akmyrat 2014년 5월 26일
thanks a lot Cedric for answer. Yep i made mistake like that 8*21*12=2016.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2014년 5월 26일

댓글:

2014년 5월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by