Cannot call INPUT from EVALC. in my code

조회 수: 15 (최근 30일)
Hanming
Hanming 2024년 3월 6일
댓글: Hanming 2024년 4월 3일
x=input('x=[1,2,3,4]');
sizex=size(x);
a=sizex(1);
b=sizex(2);
if a==1&&b==1
value=x;
position=1;
elseif (a==1&&b~=1)||(b==1&&a~=1)
value=x(1);
for i=1:length(x)
if x(i)>value
value=x(i);
position=i;
end
end
else a~=1&&b~=1
position=ones(1,b);
for ii=1:b
for jj=1:a
if x(jj,ii)>value(ii)
value(ii)=x(jj,ii);
position(ii)=jj;
end
end
end
end
a=input('output:');
if a==1
value
elseif a==2
value
position
else
error('error')
end

답변 (1개)

Sanju
Sanju 2024년 3월 11일
Hi Hanming,
I understand that you want call “input” from “evalc” function.
In the provided code, the evalc function is not necessary because there is no need to evaluate any dynamically generated code or expressions. The code is written in a straightforward manner and does not require the use of evalc to execute any additional code.
MATLAB's “evalc” function evaluates the specified expression or statements that are stored as strings and captures anything that would normally be written to the Command Window in results. MATLAB prevents the use of input within “evalc” to avoid potential issues with unexpected user interaction when evaluating code. It can be useful in certain scenarios, such as when you want to dynamically generate and execute code based on user input or when you want to evaluate expressions stored in variables.
You can also refer to the following documentation links for more information,
Hope this helps!
  댓글 수: 1
Hanming
Hanming 2024년 4월 3일
Thank you for your reply, I have been busy with exams these last few weeks and didn't see your reply.

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

카테고리

Help CenterFile Exchange에서 数学에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!