Cannot call INPUT from EVALC. in my code

4 次查看(过去 30 天)
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.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!