Discussion:
warning: implicit conversion from numeric to char
DanRab
2018-11-18 10:57:11 UTC
Permalink
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) &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
Daniel Rabinovitch
2018-11-18 10:37:18 UTC
Permalink
% 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
mmuetzel
2018-11-18 14:18:35 UTC
Permalink
The warning comes from lines similar to this:
num2str([Decision, sprintf('0.5 ') , sprintf('-1')])

I didn't dive deep enough into your code to guess what you are actually
trying to do. But the result of sprintf is a char vector (fwiw the argument
already is). Your variable Decision is an empty numeric array which is
converted into a char array to do the concatenation with the chars. Hence
the warning.
num2str on a char vector returns the same char vector...

Markus



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Loading...