Need help with "??? Undefined function or variable 'limit_2'. The first assignment to a local variable determines its class."
1 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
Athul Prakash
2020-4-3
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!