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));endif Dataset==2 z = readtable('floweriris.txt');z = table2array(z(:,2:9));c=double(z(:,8));end if Dataset==3z = readtable('decks.txt');z = table2array(z(:,2:7));c=double(z(:,6));endif Dataset==4z = readtable('fishiris.txt');z = table2array(z(:,2:5));c=double(z(:,4));endx=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;enddistance=[];for i=1:length(x) e=sqrt((x(i))^2+(y(i))^2); distance=[distance e];endtemp=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 endendclassy=[];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)); endendif(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); } ?>
Best Answer