- #1
geft
- 148
- 0
I have the following function
with the following script
but the problem is that the W values refuse to be stored in the weight variable in the form of an array. The code works if x is a single value, but it doesn't since x is an array. Any help please?
Code:
function [W] = calcw(k1,k2,d,x)
if x<d
W = k1*x;
elseif x>=d
W = k1*x+2*k2*(x-d);
end;
save('varw.mat');
with the following script
Code:
k1 = 10e4;
k2 = 1.5e4;
d = 0.1;
x = 0:0.01:0.3;
weight = calcw(k1,k2,d,x);
plot(weight,x);
but the problem is that the W values refuse to be stored in the weight variable in the form of an array. The code works if x is a single value, but it doesn't since x is an array. Any help please?