Need help with "??? Undefined function or variable 'limit_2'. The first assignment to a local variable determines its class."

1 visualización (últimos 30 días)
Hello everyone. I have a task to create a programm with mex file but now i faced with diffuculties.
I entered my function and code.
I need to generate matrix, then find the sum in the whole matrix across the limit that i need to define and I need to change the numbers in the limit with the sum
This is my function
function [a, b, c] = fun(A, limit_1, limit_2)
sum = 0;
b = 0;
c = 0;
r = size (A);
a = A;
r_1 = r(1); %%количество строк
r_2 = r(2); %%количество толбцов
for i = limit_1:(limit_2)
sum = sum + a(i);
end
for i = 1:limit_1-1
a(i) = sum;
end
for i = (limit_2+1):r_1 * r_2
a(i) = sum;
end
end
This is the code
limit_1 = input ("Vvedite levyi limit = ");
limit_2 = input ("Vvedite pravyi limit = ");
A=ones(1,10);
B=ones(1,10);
for i = 1000:1000:10000
x = randi([-5,5],i,i);
tic
a = fun(A, limit_1, limit_2);
vrema=toc;
A(1,i/1000)=vrema;
codegen fun -args {zeros(i,i),1} -nargout 3
tic
a = fun_mex(A, limit_1, limit_2);
vremb=toc;
B(1,i/1000)=vremb;
end
iks=1000:1000:10000;
plot(iks,A,'-square','MarkerIndices',1:length(A))
hold on
plot(iks,B,'-square','MarkerIndices',1:length(B))
legend('matlab-func','mex-func','Location','northwest')
xlabel('Size matrix')
ylabel('Time')

Respuesta aceptada

Athul Prakash
Athul Prakash el 3 de Abr. de 2020
codegen fun -args {zeros(i,i),1} -nargout 3
I think you have forgotten to pass the third argument into the function. This leaves 'limit_2' undefined and MATLAB throws this error.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by