How do i rectify this issue "Subscript indices must either be real positive integers or logicals."

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 22 Nov 2017
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.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!