Cannot call INPUT from EVALC. in my code

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

Respuestas (1)

Sanju
Sanju el 11 de Mzo. de 2024

0 votos

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 comentario

Hanming
Hanming el 3 de Abr. de 2024
Thank you for your reply, I have been busy with exams these last few weeks and didn't see your reply.

Iniciar sesión para comentar.

Categorías

Más información sobre App 构建 en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 6 de Mzo. de 2024

Comentada:

el 3 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!