Discussion:
Implict converiso from numeric to char
DanRab
2018-11-18 10:36:18 UTC
Permalink
Hi!

I keep getting this error when I run my code "warning: implicit conversion
from numeric to char"

I have no idea why. I have tried sprinf, matstr, num2str.

Any help will be appreciated!

Here is 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) &amp;&amp; (fL&lt;leftTol) &amp;&amp; (fR
&lt; rightTol))
Decision = num2str([Decision, sprintf('-1 ')])
elseif (mu*cos(theta)&lt;(sin(theta)) &amp;&amp; (fL>leftTol) && (fR <
rightTol))
Decision = num2str([Decision, sprintf('-1 '), sprintf(' 0.5L')])
elseif (mu*cos(theta)<(sin(theta)) && (fL<leftTol) &amp;&amp; (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) &amp;&amp; (fR &lt;
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) &amp;&amp; (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
Loading...