DanRab
2018-11-18 10:57:11 UTC
Hi!
I have no idea why I keep getting this error or how to fix it. I have tried
sprintf, numstr, mat2str etc.
ANy helpp will be appreciated!
Here is a copy of the code:
% A function to determine whether a load placed on a plane which
% is supported by a pair of springs will slide or not. The
% function accepts as input arguments LoadWeight and LoadPosition.
% The function outputs a Decision. { }
% A function to determine whether a load placed on a plane which
% is supported by a pair of springs wileftTol slide or not. The
% function accepts as input arguments LoadWeight and LoadPosition.
% The function outputs a Decision. { }
% The function reads an external data file which specifies the
% assembly parameters. i.e. Spring constants and spring positions.
% Function caleftTol is as foleftTolows: Out1 = Slide(Arg1,Arg2)
% Student number 809243
function [Decision, InclinationAngle] = Student809243(LoadWeight,
LoadPosition)
AssemblyData = csvread('AssemblyParameters.csv'); % This reads the
AssemblyParameters
%dlmread('AssemblyParameters.csv')
M=AssemblyData;
kl=M(1,1);
kr=M(1,2);
xl=M(1,3);
xr=M(1,4);
xm=M(1,5);
leftTol=M(1,6);
rightTol=M(1,7);
mu=M(1,8);
W = [(LoadWeight);(-1*LoadWeight*LoadPosition)];
N = [kl,kr;(kl*xl),(kr*(xm+xl))];
% inverse(N)
D = inverse(N)*W; %[delta Y_l; deltaY_r]
theta = atan((D(2,1)-D(1,1))/xm);
InclinationAngle=theta;
a = mu*cos(theta);
b = sin(theta);
LoadWeightNormal = LoadWeight*cos(theta);
LoadWeightTang = LoadWeight*sin(theta);
fL = (kl*D(1,1));
fR = (kr*D(2,1));
if LoadPosition > M(1,5)
disp('0')
end
Decision = [];
%accordig to maths provided if mu*costhetha < sintheta then object will
slide
%if mu*costhetha > sintheta then object will stay
%slide
if (mu*cos(theta)<sin(theta) && (fL<leftTol) && (fR
< rightTol))
Decision = num2str([Decision, sprintf('-1 ')])
elseif (mu*cos(theta)<(sin(theta)) && (fL>leftTol) && (fR <
rightTol))
Decision = num2str([Decision, sprintf('-1 '), sprintf(' 0.5L')])
elseif (mu*cos(theta)<(sin(theta)) && (fL<leftTol) && (fR >
rightTol))
Decision = num2str([Decision ,sprintf('-1 '), sprintf(' 0.5R')])
elseif (mu*cos(theta)<(sin(theta)) && (fL>leftTol) && (fR > rightTol))
Decision = num2str([Decision, sprintf('0.5 ') , sprintf('-1')])
%stay
elseif (mu*cos(theta)>sin(theta)&& (fL<leftTol) && (fR <
rightTol))
Decision = num2str([Decision, sprintf('1')])
elseif (mu*cos(theta)>sin(theta)&& (fL>leftTol) && (fR < rightTol))
Decision = num2str([Decision, sprintf('1'), sprintf(' 0.5L')])
elseif (mu*cos(theta)>sin(theta)&& (fL<leftTol) && (fR >
rightTol))
Decision = num2str([Decision, sprintf('1 '), sprintf(' 0.5R')])
elseif (mu*cos(theta)>sin(theta)&& (fL>leftTol) && (fR > rightTol))
Decision = num2str([Decision, sprintf('0.5 ') , sprintf('1')])
endif
end
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
I have no idea why I keep getting this error or how to fix it. I have tried
sprintf, numstr, mat2str etc.
ANy helpp will be appreciated!
Here is a copy of the code:
% A function to determine whether a load placed on a plane which
% is supported by a pair of springs will slide or not. The
% function accepts as input arguments LoadWeight and LoadPosition.
% The function outputs a Decision. { }
% A function to determine whether a load placed on a plane which
% is supported by a pair of springs wileftTol slide or not. The
% function accepts as input arguments LoadWeight and LoadPosition.
% The function outputs a Decision. { }
% The function reads an external data file which specifies the
% assembly parameters. i.e. Spring constants and spring positions.
% Function caleftTol is as foleftTolows: Out1 = Slide(Arg1,Arg2)
% Student number 809243
function [Decision, InclinationAngle] = Student809243(LoadWeight,
LoadPosition)
AssemblyData = csvread('AssemblyParameters.csv'); % This reads the
AssemblyParameters
%dlmread('AssemblyParameters.csv')
M=AssemblyData;
kl=M(1,1);
kr=M(1,2);
xl=M(1,3);
xr=M(1,4);
xm=M(1,5);
leftTol=M(1,6);
rightTol=M(1,7);
mu=M(1,8);
W = [(LoadWeight);(-1*LoadWeight*LoadPosition)];
N = [kl,kr;(kl*xl),(kr*(xm+xl))];
% inverse(N)
D = inverse(N)*W; %[delta Y_l; deltaY_r]
theta = atan((D(2,1)-D(1,1))/xm);
InclinationAngle=theta;
a = mu*cos(theta);
b = sin(theta);
LoadWeightNormal = LoadWeight*cos(theta);
LoadWeightTang = LoadWeight*sin(theta);
fL = (kl*D(1,1));
fR = (kr*D(2,1));
if LoadPosition > M(1,5)
disp('0')
end
Decision = [];
%accordig to maths provided if mu*costhetha < sintheta then object will
slide
%if mu*costhetha > sintheta then object will stay
%slide
if (mu*cos(theta)<sin(theta) && (fL<leftTol) && (fR
< rightTol))
Decision = num2str([Decision, sprintf('-1 ')])
elseif (mu*cos(theta)<(sin(theta)) && (fL>leftTol) && (fR <
rightTol))
Decision = num2str([Decision, sprintf('-1 '), sprintf(' 0.5L')])
elseif (mu*cos(theta)<(sin(theta)) && (fL<leftTol) && (fR >
rightTol))
Decision = num2str([Decision ,sprintf('-1 '), sprintf(' 0.5R')])
elseif (mu*cos(theta)<(sin(theta)) && (fL>leftTol) && (fR > rightTol))
Decision = num2str([Decision, sprintf('0.5 ') , sprintf('-1')])
%stay
elseif (mu*cos(theta)>sin(theta)&& (fL<leftTol) && (fR <
rightTol))
Decision = num2str([Decision, sprintf('1')])
elseif (mu*cos(theta)>sin(theta)&& (fL>leftTol) && (fR < rightTol))
Decision = num2str([Decision, sprintf('1'), sprintf(' 0.5L')])
elseif (mu*cos(theta)>sin(theta)&& (fL<leftTol) && (fR >
rightTol))
Decision = num2str([Decision, sprintf('1 '), sprintf(' 0.5R')])
elseif (mu*cos(theta)>sin(theta)&& (fL>leftTol) && (fR > rightTol))
Decision = num2str([Decision, sprintf('0.5 ') , sprintf('1')])
endif
end
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html