# unable to perform assignment because left and right sides have a different number of elements

6 views (last 30 days)
john_arle on 28 Mar 2019
Commented: john_arle on 28 Mar 2019
Hello there,
I have this problem when implementing my main and my function called "due".
MAIN
clc
clear
format long
set(groot,'DefaultAxesFontSize',14)
set(groot,'DefaultLineLineWidth',1.5)
sample = generateGoldCodeSampled(1,6.5e6,1.023e6,1);
corr = zeros(10,6500);
for i = 1:10
corr(i,:) = due(i, sample);
figure (i)
plot (0:6499, corr(1,(0:6499)+1))
grid on
end
FUNCTION DUE
function corr = due(PRN, signal_2)
pseudo_signal = generateCAcode(PRN);
signal_1 = zeros(1,6500);
signal_1(1:1023) = pseudo_signal(1:1023);
signal_1(1024:2047) = pseudo_signal(1:1023);
signal_1(2048:3071) = pseudo_signal(1:1023);
signal_1(3072:4095) = pseudo_signal(1:1023);
signal_1(4096:5119) = pseudo_signal(1:1023);
signal_1(5120:6143) = pseudo_signal(1:1023);
signal_1(6144:6500) = pseudo_signal(1:1023);
corr = zeros(1,6500);
for k = 1:6500
for j = 1:6500
if (j+k-1 <= 6500)
corr(1,k) = corr(1,k)+signal_1(j)*signal_2(j+k-1);
else
corr(1,k) = corr(1,k)+signal_1(j)*signal_2(j+k-6501);
end
end
end
end
In what way is the array assignment operation wrong?
Indeed, this is the error that I get!
Unable to perform assignment because the left and right sides have a different number of elements.
Error in due (line 7)
signal_1(1024:2047) = pseudo_signal(1:1023);
Error in maindue (line 13)
corr(i,:) = due(i, sample);
PS
pseudosignal is just a sequence of +1 and -1.
Thank you!

Jan on 28 Mar 2019
Edited: Jan on 28 Mar 2019
The error message is clear: The number of elements of the left and righ side differs. Try this:
% signal_1(1024:2047) = pseudo_signal(1:1023);
size(1024:2047)
size(1:1023)
It is not clear, how you want to concatenate a [1 x 1023] vector to get a [1 x 6500] vector. The last block 6144:6500 has 357 elements only and you cannot assign a [1 x 1023] vector to it.
Maybe you mean:
signal_1 = repmat(pseudo_signal(1:1023), 1, 7);
but this has 7161 elements, not 6500.

john_arle on 28 Mar 2019
Hello Jan,
thank you for your answer, and sorry to bother for that stupid mistake. Yes, I want to concatenate the array 6 times plus the first 357 element of itself. Do you know a rapid way to do it?
john_arle on 28 Mar 2019
I found out. thanks.