How do i rectify this issue "Subscript indices must either be real positive integers or logicals."
2 次查看(过去 30 天)
显示 更早的评论
c1= zeros(250,2);
for w = 0:1:50
k=(w-1)/0.1;
if (w)>50 % if the package is greater than 50Kg, the package is overweight
fprintf('error package is overweight');
elseif (w)<=1.0 %if the weight is less than 1kg, then the cost is £10
c=10;
%fprintf('$%.2f \n',c)
elseif (w)<35 % if the weight is greater than 1Kg but less than 35Kg, a surcharge of £1.45 is added for every 100g
c=((10+(1.45*k)));
%fprintf('$%.2f \n',c)
elseif (w)>35.0 && (w)<=50 % if the weight is greater than 35Kg but less than 50Kg, an extra charge of £10 is added
c=20+(1.45*k);
%fprintf('$%.2f \n',c)
end
c1(w,:) = [w c(w)]
end
%plot(w,c1);
% xlabel('Weight of the package');
% ylabel('Cost of the delivery');
% title('The Relation Between Weight of a package and Cost of sending it');
% grid on
%end
0 个评论
采纳的回答
Walter Roberson
2017-11-22
You have
for w = 0:1:50
so w starts from 0.
You then compute c with no subscript, assigning a scalar each time.
You then have
c1(w,:) = [w c(w)]
which attempts to examine subscripted c. Because c is a scalar, the only possible valid subscript is 1 . But you are indexing with w, which is 0.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!