Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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')

Réponse acceptée

Athul Prakash
Athul Prakash le 3 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by