m.muner
m.muner

Reputation: 15

how to plot a the given function?

i have the fallowing matlab code

close all
Pu=1;
No=1e-8;
B=20e6;
u=1:20;
C_CDMA=u*B*log2(1+Pu./(B*No+(u-1)*Pu));
plot(u,C_CDMA/1e6);hold on
xlabel('Noise Power Spectral Density (No)')
ylabel('Capacity (Mbps)')
legend('CDMA','OFDMA')

the equation C_CDMA should be calculated for each value of (u) . and then plot the result as the values of the function with u values but this code give me the fallowing error " error using m times Inner matrix dimensions must agree". what is the wrong ?

Upvotes: 0

Views: 47

Answers (1)

T T
T T

Reputation: 154

I hope simple solution would be to put u in for loop as follows

close all
Pu=1;
No=1e-8;
B=20e6;
C_CDMA = zeros(1,20)

for u=1:20
    C_CDMA(u) = u*B*log2((1+Pu)/(B*No+(u-1)*Pu));
end

u=1:20;
figure,
plot(u,C_CDMA/1e6);hold on
xlabel('Noise Power Spectral Density (No)')
ylabel('Capacity (Mbps)')
legend('CDMA','OFDMA') 

why two legends for a single graph

Upvotes: 1

Related Questions