comPort = 'COM7';
if (~exist('serialFlag','var'))
[arduino.s,serialFlag]=setupSerial(comPort);
end
if(~exist('h','var') || ~ishandle(h))
h=figure(1);
end
if(~exist('text1','var'))
text1=uicontrol('Style','Text','String','X: 0 degrees',...
'pos',[450 100 100 25],'parent',h);
end
if(~exist('text2','var'))
text2=uicontrol('Style','Text','String','Y: 0 degrees',...
'pos',[450 75 100 25],'parent',h);
end
if(~exist('button','var'))
button=uicontrol('Style','togglebutton','String','Stop & Close Serial Port',...
'pos',[0 0 200 25],'parent',h);
end
weights = [ 0 20 50 70 100 120 150 170 200 220 250];
m = zeros(length(weights),1);
for i = 2:length(weights)
mbox=msgbox(['Place' num2str(weights(i)) ' grams on thr FSR']); uiwait(mbox);
m(i)=readFSR(fsr);
while(m(i) < m(i-1)) || m(i) ==0
m(i) = readFSR(fsr);
end
end
p1=polyfit(m,weights,2);
myaxes=axes('xlim',[-20 20], 'ylim', [-20 20],'zlim',[-0 250]);
view(3);
grid on;
axis equal;
hold on;
[xsphere, ysphere, zsphere]=sphere();
h(1)=surface(xsphere, ysphere, zsphere);
combinedobject = hgtransform('parent',myaxes);
set(h, 'parent',combineobject)
drawnow;
while (get(button, 'value')==0)
[voltage]=readFSR(fsr);
mass = polyval(p1, voltage);
if (mass>0)
force=mass*9.81;
set(text1,'String',['Mass :' num2str(round(mass)) 'grams'])
set(text2,'String',['Force :' num2str(round(force)) 'N'])
translation = makehgtform('translate',[0 0 mass]);
set(combinedobject,'matrix',translation);
scaling=makehgtform('scale',mass/10);
set(combinedobject,'matrix',scaling);
set(combinedobject, 'natrix',translation*scaling);
end
pause(0.1);
end
closeSerial;
WHY THİS ERROR ?
Attempt to execute SCRIPT fsr as a function:
C:\Users\ismet\Desktop\fsr.m
Error in fsr (line 28)
m(i)=readFSR(fsr);
9 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_442413
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_442413
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_484280
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_484280
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_486413
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_486413
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_497694
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_497694
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_519459
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_519459
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_654071
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_654071
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_778285
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_778285
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_970950
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_970950
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_971073
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/93148-why-do-i-receive-the-error-attempt-to-execute-script-filename-as-a-function#comment_971073
Sign in to comment.