converting float to integer makes problem
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mustafa Duran
am 7 Dez. 2023
Kommentiert: Mustafa Duran
am 8 Dez. 2023
My code is:
% Uzunluk(cm)
e=2.25; a=15.75; b=13.5; g=44.25; L=90.50;
%Mesnet yükleri(kg)
C=3750; B=3750; A=6500; D=3750;
%Yayılı yükler(kg/cm)
q1=2*C*(L-e)/(L^2); q2=2*A*(L-a)/(L^2); q3=2*B*(L-a-b)/(L^2); q4=2*D*(L-a-b-g)/(L^2);
%Süperpozisyonla ayrılmış parçaların momentleri(kg.cm)%
%M1=-q1*(x^2)/2; M2=-q1*(x^2)/2+ C*(x-e);
%M3=-q2*(x^2)/2; M4=-q2*(x^2)/2+ A*(x-a);
%M5=-q3*(x^2)/2; M6=-q3*(x^2)/2+ B*(x-a-b);
%M7=-q4*(x^2)/2; M8=-q4*(x^2)/2+ D*(x-e);
% Süperpozisyonla ayrılan parçaların birleştirilmesi sonucu net
% momentler(kg.com)
for x=0:0.025:L
y=int64(40*x)+1;
if (0<=x) && (x<=e)
y
M(y)=-(x^2)/2*(q1+q2+q3+q4);
elseif (e<x) && (x<=a)
y
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e);
elseif (a<x) && (x<=a+b)
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e)+A(x-a);
elseif (a+b<x) && (x<=a+b+g)
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e)+A(x-a)+B(x-a-b);
elseif (a+b+g<x) && (x<=L)
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e)+A(x-a)+B(x-a-b)+D(x-a-b-g);
end
end
Runner finished first if loop and after that even if it calculates the value of y as 92 it gave me that error:
Array indices must be positive integers or logical values.
Error in untitled2 (line 23)
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e);
error.
How can i fix that?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Dez. 2023
int64(y);
That line takes a value of y as input, and creates a uint64 equivalent of the input value, and stores the value in the semi-hidden variable named ans and then otherwise throws away the result because the semi-colon tells MATLAB not to display the output.
One thing it does not do is store the result into y . If you want the result to be written into y then you need to store the result into y
4 Kommentare
Walter Roberson
am 7 Dez. 2023
x = (y-1)/40;
That is not going to be an integer.
M(y)=-(x^2)/2*(q1+q2+q3+q4)+C(x-e);
but x-e is used as a subscript
C=3750; B=3750; A=6500; D=3750;
... a subscript into the scalar value C
Reminder: MATLAB has absolutely no implied multiplication. Not anywhere . Not even inside the internal language of the Symbolic Mathematics toolbox.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!