Cannot call INPUT from EVALC. in my code
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Sanju
am 11 Mär. 2024
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!
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!