Error: This statement is incomplete.

6 views (last 30 days)
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 Comments
Steven Lord
Steven Lord on 16 Mar 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
Dimitris Papazacharias on 16 Mar 2021
there you have it ! Thank you for your time!

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 16 Mar 2021
So the command that's being executed looks like it is:
submittedmatlab -sd F:\MATLAB\matlab2020\bin\matlab.exe -r knn_func(1, 1, 1,1)
I understand why you're receiving this error, but there's also another thing odd about this command.
Assuming submittedmatlab is a command to launch MATLAB using the executable and pass some startup options into it, the value for the -sd option should be the directory in which MATLAB should start rather than the full path of the executable.
The value that's being specified for the -r startup option as the code to be executed is "knn_func(1," [quotes added to distinguish where the command ends from where the sentence ends.]. The space ends the command since it is not enclosed in quotes. Try wrapping that call in quotes as per the example for the -r option using disp on this documentation page. Alternately you might want to use the -batch option instead (with the quotes as well.)
submittedmatlab -sd F:\MATLAB\matlab2020\bin\matlab.exe -r 'knn_func(1, 1, 1,1)'
  1 Comment
Dimitris Papazacharias
Dimitris Papazacharias on 17 Mar 2021
All I did was to change the paths like the ones below, and it works perfectly! Thank you for your guidance.
if($NameofAlg == "1") {
$command = 'F:\MATLAB\matlab2020\bin\matlab -r "knn_func('.$dataset.', '.$fromvar.', '.$tovar.','.$k.')"'; }
else{
$command = 'F:\MATLAB\matlab2020\bin\matlab -r "kmeans_func('.$dataset.', '.$fromvar.', '.$tovar.','.$k.')"'; }
echo($command);
exec($command);

Sign in to comment.

More Answers (1)

ANKUR KUMAR
ANKUR KUMAR on 16 Mar 2021
You need to provide sufficient arguments while calling the function.
knn_func(2,4,8,1)
  1 Comment
Dimitris Papazacharias
Dimitris Papazacharias on 16 Mar 2021
thats what iam trying to do with the post method. get the table data and insert them on my matlab func

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!