using math operation as string in array on an expression

조회 수: 3 (최근 30일)
yonatan gerufi
yonatan gerufi 2014년 5월 23일
편집: Mischa Kim 2014년 5월 23일
Hi all,
i need to do some math operation on elements in certain order, as:
3+4, 3-4, 3*4, 3/4, 3^4
i thought using a string array
['+','-','*'..]
and somehow to do
3 arr[i] 4
but i just can't make it work! any ideas?

채택된 답변

Mischa Kim
Mischa Kim 2014년 5월 23일
편집: Mischa Kim 2014년 5월 23일
yonatan, you are on the right track:
carray = {'3+4','3/4'};
res = eval(carray{2})
res =
0.750000000000000

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by