订阅的维度不匹配

时间:2018-02-09 18:01:05

标签: matlab

我正在尝试实现2x2 MIMO系统无均衡,并且我一直收到错误“Subscripted assignment dimension mismatch”。这是我的matlab代码:

clc; clear; close all;
N = 100;
Eb_No_dB = (-1 : 20);
n_Tx = 2;
n_Rx = 2;

for kk = 1:N
    for ii = 1 : length(Eb_No_dB)

        % Transmitter
        s = rand(2, 1)>0.5;  %% generate input bits with equal probabilities
        x = 2 * s - 1; %% BPSK Modulation
        w = 1/sqrt(2) * (randn(n_Tx,1) + 1i * randn(n_Tx,1));  %% AGWN
        h = 1/sqrt(2) * (randn(n_Tx,n_Rx) + 1i * randn(n_Tx,n_Rx));  %% Rayleigh Channel
        y = h'*x + 10^(-Eb_No_dB(ii)/20) * w;  %% transmitted signal through the channel
        h_hat = squeeze(sum(h, 2));
        % Receiver
        y_out = y./h_hat;

        % hard decision decoding
        y_r = real(y_out)>0;
        n_Error(ii) = size(find((s - y_r), 1));

    end

end
Sim_BER = n_Error/N;
Eb_No_Lin = 10.^(Eb_No_dB/10);
BER_Ray_Theory_Rx1 = 0.5 .* (1 - sqrt(Eb_No_Lin./(1 + Eb_No_Lin)));  %% BER due to TX1
p = 1/2 - 1/2*(1+1./Eb_No_Lin).^(-1/2);
BER_Ray_Theory_Rx2 = p.^2.*(1+2*(1-p)); 
semilogy(Eb_No_dB, Sim_BER, 'k*-', 'LineWidth', 2);
hold on;
semilogy(Eb_No_dB, BER_Ray_Theory_Rx1, 'ms-', 'LineWidth', 2);
semilogy(Eb_No_dB, BER_Ray_Theory_Rx2, 'R>-', 'LineWidth', 2);
axis([-1 20 10^-7 1]);
grid on;
xlabel('Eb-No-dB', 'FontSize', 12); ylabel('BER', 'FontSize', 12);
legend('SimulatioN-BER (Rx=Tx=2 WITH ZF)', 'Theory-BER (Tx=Rx=1)', 'Theory-BER(Tx2=1,Rx=2, MRC');
title('BER FOR BPSK MODULATION WITH 2X2 MIMO & ZERO-FORCING EQUALIZER');

1 个答案:

答案 0 :(得分:0)

如果您查看完整的错误消息,则会显示错误的位置:

Subscripted assignment dimension mismatch.

Error in SOcode (line 22)
        n_Error(ii) = size(find((s - y_r), 1));

在此,您已限制find找到第一个索引,其中(s - y_r) ~= 0始终返回标量或空数组。根据{{​​3}}的文档,输出始终是行向量,即使对于标量也是如此,因此元素的数量始终为>= 2n_Error(ii)是一个标量索引,因此无法容纳多个元素,从而导致上述错误。

要解决此问题,请使用sizenumel代替size