# DimensionMismatch("tried to assign 15-element array to 1×5 destination")

I keep struggling to correct this error in my code “DimensionMismatch(“tried to assign 15-element array to 1×5 destination”)”. I kindly need help to correct this code to get it running correctly please. Thank you. My code is attached

``````
a1=[0, 2.5, -2.5, 2, -2.5] # x cordinates of the circle
b1=[0, 0.3, 0.25, -2.5, -2.25]  # y cordinates of the circle

r1= [2, 2 , 2 , 2 ,2] # Radiuus of circle
A=[1 0 0 0 1;0 0 0 1 1;1 0 0 0 1;0 0 1 1 1;0 0 0 1 1; 0 1 0 0 1;0 0 1 1 0;0 0 0 1 0;
1 0 0 0 0;1 1 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 1 0 0;1 0 0 0 0;0 0 0 1 0 ]
m,n=size(A)
CoveredItems=zeros(Int64,m)
Coverage=zeros(Int64,n)
for i in 1:n
sumval=sum(A[:,i])
Coverage[i]=sumval
end
SelectedSolution=zeros(Int64,n)
maxval,maxpos=findmax(Coverage)
CoveredItems=A[:,maxpos]
SelectedSolution[maxpos]=1
count=maxval
println(maxpos)

UncoveredItems=zeros(Int64,m)
for i in 1:m
if (CoveredItems[i]==0)
UncoveredItems[i]=1
else
A[i,:]=zeros(Int64,m)
end
end

print(A)

``````

The problem is this line:

``````A[i,:] = zeros(Int64,m)
``````

The left side has the dimension 1x5 while the right side has 15 elements.

Can you please suggest what I do to correct this?
I am quite confused here.

I think you need to swap the `m` for an `n` i.e.

``````A[i,:]=zeros(Int64, n)
``````

You could also write this as

``````A[i, :] .= 0
``````

and this would have better performance as `zeros(Int64, n)` allocates a vector every single time you call it.

1 Like

Thank you very much. This works now.