Error: This statement is incomplete.
Mostrar comentarios más antiguos
Hello everyone! I've made this function on Matlab and I want to input variables to it from my php table-page.The problem is that I get the error above when i call it (even though it works perfectly manually). Can anyone see where the problem is?
(Iam giving the matlab code, the php code and the error below). Thank you in Advance, for your time!
Error:

Matlab code:
function knn_func(dataset,fromvar,tovar,k)
Dataset=dataset;
Fromvar=fromvar;
Tovar=tovar;
if Dataset==1
z = readtable('loans.txt');
z = table2array(z(:,2:5));
c=double(z(:,4));
end
if Dataset==2
z = readtable('floweriris.txt');
z = table2array(z(:,2:9));
c=double(z(:,8));
end
if Dataset==3
z = readtable('decks.txt');
z = table2array(z(:,2:7));
c=double(z(:,6));
end
if Dataset==4
z = readtable('fishiris.txt');
z = table2array(z(:,2:5));
c=double(z(:,4));
end
x=double(z(:,Fromvar));
y=double(z(:,Tovar));
plot(x,y,'b.','linewidth',2);
xlabel('x');
ylabel('y');
title('Income Dataset');
hold on;
m=[];
k1=k;
pos = randi(length(x));
for i=1:length(x)
if(c(i)==0)
plot(x(i),y(i),'r+','linewidth',4);
else
plot(x(i),y(i),'g+','linewidth',4)
end
hold on;
end
distance=[];
for i=1:length(x)
e=sqrt((x(i))^2+(y(i))^2);
distance=[distance e];
end
temp=0;
gemp=0;
for i=1:length(distance)
for j=1:(length(distance)-i)
if(distance(j)>distance(j+1))
temp=distance(j);
distance(j)=distance(j+1);
distance(j+1)=temp;
gemp=c(j);
c(j)=c(j+1);
c(j+1)=gemp;
end
end
end
classy=[];
freq0=0;
freq1=0;
for i=1:k
classy=[classy c(i)];
if(c(i)==0)
freq0=freq0+(1/distance(i));
else
freq1=freq1+(1/distance(i));
end
end
if(freq0==freq1)
output=mode(classy);
elseif(freq0>freq1)
output=0;
else
output=1;
end
;
xlabel('x');
ylabel('y');
title('knn classification on Income data');
end
PhP Code:
<?php
if (isset($_POST['submit-btn'])) {
echo 'submitted';
$id = $_POST['id'];
$dataset = $_POST['dataset'];
$fromvar =$_POST['fromvar'];
$tovar = $_POST['tovar'];
$algorithm = $_POST['algorithm'];
$k = $_POST['k'];
$inputDir = "F:\MATLAB\matlab2020\bin\matlab.exe";
$NameofAlg = $algorithm;
if($NameofAlg == "1") {
$command = "matlab -sd ".$inputDir." -r knn_func(".$dataset.", ".$fromvar.", ".$tovar.",".$k.")"; }
else{
$command = "matlab -sd ".$inputDir." -r kmeans_func(".$dataset.", ".$fromvar.", ".$tovar.",".$k.")"; }
echo($command);
exec($command);
}
?>
2 comentarios
Steven Lord
el 16 de Mzo. de 2021
Can you show us the command that was echoed and then used to launch the MATLAB session in which the error occurred? I think seeing $command in echo($command); might help the debugging process.
Dimitris Papazacharias
el 16 de Mzo. de 2021
Respuesta aceptada
Más respuestas (1)
ANKUR KUMAR
el 16 de Mzo. de 2021
You need to provide sufficient arguments while calling the function.
knn_func(2,4,8,1)
1 comentario
Dimitris Papazacharias
el 16 de Mzo. de 2021
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
