Clear Filters
Clear Filters

what is thing must I do?? to pass this error?

1 view (last 30 days)
Mary Jon
Mary Jon on 27 Sep 2013
Answered: Walter Roberson on 27 Sep 2013
??? Error using ==> horzcat
All matrices on a row in the bracketed expression must have the
same number of rows.
Error in ==> SOR at 64
kernel = [0, W1, 0; W3, 0, W4; 0, W2, 0];
matrix(v) consist of (110 by 32 )rows,column respectivly
the error in this part of code !!!!
E= ones(111,33)*8.854*10^(-12);
for i=5
for j = [2:13, 22:32]
if i==105
E(i-1,j-1)=8.85*10.^(-11); %%permittivity of interface region
E(i,j-1)=8.85*10.^(-11);
end
W1(i,j)=(h.^2).*(E(i,j)+E(i,j-1));
W2(i,j)=(h.^2).*(E(i-1,j)+E(i-1,j-1));
W3(i,j)=E(i,j)+E(i-1,j);
W4(i,j)=E(i,j-1)+E(i-1,j-1);
W(i,j)=W1(i,j)+W2(i,j)+W3(i,j)+W4(i,j);
kernel = [0, W1, 0; W3, 0, W4; 0, W2, 0];
filtered = conv2(vk, kernel, 'same');
vk = (1-w)*vk + filtered./W;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
what is horzcat mean?

Answers (2)

dpb
dpb on 27 Sep 2013
Just an aside, not a single one of your tags has anything whatsoever to do with the question/problem...
'horzcat' is the function Matlab calls under the hood for the 'horizontal concatenation' operation. You asked for horizontal (as opposed to vertical) concatenation when you wrote
kernel = [0, W1, 0; ...
that's asking to concatenate the array W1 with zeros but you wrote a scalar zero instead of a vector. There's only one row in '0' but some number >1 in W1.
You need
z=zeros(size(W1,1),1); % vector of zeros same row size as W1
kernel=[z W1 z; ...

Walter Roberson
Walter Roberson on 27 Sep 2013
You have "for i=5". Inside that you assign to W1(i,j) for j = [2:13, 22:32]. So W1 is going to end up being at least 5 by 32.
You have
[0, W1, 0
as the first row of "kernel". But "0" and "0" are 1 x 1, and W1 is at least 5 x 32. MATLAB will not know that you want the "0" to be expanded out to have the right number of rows to create a column vector of 0's to paste against the first and last columns of "W1". And MATLAB will especially not know that the "0" is intended to fill out to a 2D array of 0's to fit nicely against W1 to the right and W3 below it.
Try this:
Z = zeros(size(W1));
kernel = [Z, W1, Z; W3, Z, W4; Z, W2, Z];
If you still get errors then the implication would be that W1, W2, W3, W4 are not all the same size, in which case figuring out the right size of block of 0's becomes more complex.

Community Treasure Hunt

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

Start Hunting!