Cannot call INPUT from EVALC. in my code

15 Ansichten (letzte 30 Tage)
Hanming
Hanming am 6 Mär. 2024
Kommentiert: Hanming am 3 Apr. 2024
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

Antworten (1)

Sanju
Sanju am 11 Mär. 2024
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 Kommentar
Hanming
Hanming am 3 Apr. 2024
Thank you for your reply, I have been busy with exams these last few weeks and didn't see your reply.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 数学 finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!