Unable to perform assignment because the left and right sides have a different number of elements.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I keep getting the error message above when I try to run this loop, I need to count the number of leap years there are and add up the total number of them equal to L, but when I run this loop, I only ever get L=1 from this for the answer, or it will give me the error above. It says that this error is from line 7: L(i)=L+0;
When I add (i) to the second L on the other side of the = it then tells me that the Index exceeds the number of array elements (1).
x=[1:1:2021];
L(1)=0
for i = 1:2021
if mod(x(i),400) == 0
L(i)=L+1;
elseif (mod(x(i),100) == 0 ~= mod(x(i),400))
L(i)= L+0;
else (mod(x(i),4) == 0 ~=- mod(x(i),100))
L(i) = L+1
end
end
0 Kommentare
Antworten (1)
KSSV
am 27 Jan. 2022
Bearbeitet: KSSV
am 27 Jan. 2022
You have not indexed L, so it was 2x1 vector and you are trying to save it into a single element which popped a error. Consider the below modified code.
x=1:1:2021;
L = zeros(2021,1) ;
L(1)=0 ;
for i = 2:2021
if mod(x(i),400) == 0
L(i)=L(i-1)+1;
elseif (mod(x(i),100) == 0 ~= mod(x(i),400))
L(i)= L(i-1)+0;
else (mod(x(i),4) == 0 ~=- mod(x(i),100));
L(i) = L(i-1)+1 ;
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Spectral Estimation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!