필터 지우기
필터 지우기

How to calculate a printed arithmetic

조회 수: 2 (최근 30일)
Ernest Adamtey
Ernest Adamtey 2021년 7월 31일
댓글: Chunru 2021년 8월 1일

for A=1:3
if A==1
fprintf('2')
elseif A==2
fprintf('+')
elseif A==3
fprintf('3')
end
end
I want represent numbers and operations with code numbers. But when I run this code I get an output
2+3>>
but it doesnt give me the solution. I want to get an output which gives me 5. Please help

채택된 답변

Chunru
Chunru 2021년 7월 31일
str = [];
for A=1:3
if A==1
str = [str sprintf('2')];
elseif A==2
str = [str sprintf('+')];
elseif A==3
str = [str sprintf('3')];
end
end
str
str = '2+3'
eval(str)
ans = 5
  댓글 수: 2
Ernest Adamtey
Ernest Adamtey 2021년 7월 31일
It worked thank you very much.
Chunru
Chunru 2021년 8월 1일
If it worked, please consider to accept the answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by