MATLAB Answers

The variable Edj appears to change size consider preallocating

1 view (last 30 days)
VV(1:size(temp,1),d)=temp;
for j=1:n
E(d,j) = y(j,:)*VV(s+1:s+m,d) / (x(j,:)*VV(1:s,d));
end
Ecros =sum(Edj)/n
End

  0 Comments

Sign in to comment.

Accepted Answer

Gifari Zulkarnaen
Gifari Zulkarnaen on 1 Jan 2020
Edited: Gifari Zulkarnaen on 3 Jan 2020
The size of your matrix changes at every iteration. Make zero matrix before looping. For example:
Edj = zeros(d,n);
*edited for corrections from Image Analyst and Jacob Muvingi

  5 Comments

Show 2 older comments
Jacob Muvingi
Jacob Muvingi on 3 Jan 2020
I am still getting the same error, after I have done the following;
for j=1:n
Edj=zeros(d,n);
E(d,j)=y(j, :)*V(s+1:s+m,d)/ (x(j,:)*V(1:s,d));
end
Ecros=sum(Edj)/n
end
. If I use matrices with equal sizes I am not getting the error. My
x=[1 6 1.5 4 7.5 1 4.5 2 3 8 1.875 5 1.5 5.5 1.25 5 3 3 12 1.6 5.1 1.8 2 7];
y=[1 1 1 1 1 1 1 1 1 1 1 1];
Stephen Cobeldick
Stephen Cobeldick on 3 Jan 2020
"So should I write Edj=zeros(d,n);"
No, you should write what Image Analyst told you.
"I am still getting the same error..."
It is a warning, not an error.
"...after I have done the following;"
Array preallocation needs to be before the loop, e.g.:
E = zeros(d,n);
for j = 1:n
E(d,j) = ...
end
Jacob Muvingi
Jacob Muvingi on 3 Jan 2020
The issue of preallocation seem to have resolved, however getting message Matrix dimensions must agree referring to line for calculation of E(d,j). My matrices are of different sizes, y is 1*12, x is 2*12. V are weights for each x and y value.

Sign in to comment.

More Answers (0)