unable to perform assignment because left and right sides have a different number of elements
1 view (last 30 days)
Show older comments
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)
load('Ex1T2_mistery_signal.mat');
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!
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!