Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
nathan Short
nathan Short 2019 年 9 月 17 日
コメント済み: nathan Short 2019 年 9 月 17 日
Why do i get " Subscript indices must either be real positive integers or logicals." when i run my code and how can i fix it
%% problem parameters
P = 0.5*9.81; % [load N]
L = 0.5; % [Length M]
E = 69*10^6;
I = ((0.0032^3)*(0.0088))/12;
%%
x = (0:0.025:L);
v = zeros(length(x));
for i = 0.025:length(a)
a = 1/(E*I);
b = 1/12;
c = 1/16;
v(i) = a*((b*P*(i^3))-(1*c*P*(L^2)));
end

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 17 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 17 日
The error is
v(i)
%..^
In Matlab indexing, the i value must be positive interger, like 1,2,3,,,,
v(1)>> Allow
v(0)>> Not Allow
v(0.25)>> Not Allow
v(-3)>> Not Allow
v(7)>> Allow
Hope you get the sufficients hints. In your case i starts from 0.25, hence v(0.25) Not allowed.
% Define a
% ????
%% problem parameters
P = 0.5*9.81; % [load N]
L = 0.5; % [Length M]
E = 69*10^6;
I = ((0.0032^3)*(0.0088))/12;
%%
x = (0:0.025:L);
v = zeros(length(x));
i=0.025:length(a)
for j =1:length(i)
a = 1/(E*I);
b = 1/12;
c = 1/16;
v(j)= a*((b*P*(i(j)^3))-(1*c*P*(L^2)));
end
Without Loop:
% Define a
% ????
%% problem parameters
P = 0.5*9.81; % [load N]
L = 0.5; % [Length M]
E = 69*10^6;
I = ((0.0032^3)*(0.0088))/12;
%%
x = (0:0.025:L);
v = zeros(length(x));
i=0.025:length(a)
a=1/(E*I);
b=1/12;
c=1/16;
v=a*((b*P.*(i.^3))-(1*c*P*(L^2)));
Any issue let me know?
  5 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 17 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 17 日
If a=20,
the what does the following means
i = 0.025:length(a)
it return i as a single element
i=0.025
Are you sure? No Need of loop.The v becomes
v =
-46.2192
If no, What exactly you are trying to do?
nathan Short
nathan Short 2019 年 9 月 17 日
i want to return v as an array for each input of i (0;0.025;0.5). then plot the values against each other as it should display a deflection curve

サインインしてコメントする。


Image Analyst
Image Analyst 2019 年 9 月 17 日
The FAQ explains it pretty well: Click here for the FAQ on that error

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by