Error: This statement is incomplete.
조회 수: 8 (최근 30일)
이전 댓글 표시
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
Steven Lord
2021년 3월 16일
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.
채택된 답변
Steven Lord
2021년 3월 16일
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개)
ANKUR KUMAR
2021년 3월 16일
You need to provide sufficient arguments while calling the function.
knn_func(2,4,8,1)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!