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

1 回表示 (過去 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

採用された回答

Walter Roberson
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 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by