Plot is not lined up with the X axis
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Prashant Bhagat
el 12 de Ag. de 2022
Respondida: Star Strider
el 12 de Ag. de 2022
Hi,
I have a strange problem. My simulatiuon plot is not lined with the x-axis. can anyone please help me for that.
I am attaching the script here and the plot.
Script:
close all;
clear;
clc;
% Defining variables
A = 10; % Total number of transmitters
p = 0.01;
Length_of_packet = 1000; % Maximum packet length in bits
Bitrate = 100; % bit rate for each transmitter in bits/sec
Trasmission_Time = Length_of_packet/Bitrate;
Total_Time = 1000; % Total time for simulation in seconds
Zero_slot_overlapping = 0;
One_slot_overlapping = 0;
Two_slot_overlapping = 0;
Three_slot_overlapping = 0;
Four_slot_overlapping = 0;
Five_slot_overlapping = 0;
Six_slot_overlapping = 0;
Seven_slot_overlapping = 0;
Eight_slot_overlapping = 0;
Nine_slot_overlapping = 0;
Ten_slot_overlapping = 0;
User = zeros(A,Total_Time);
for k = 1:A
%User(k,:) = zeros(1,Total_Time);
for i = 1:(Total_Time-4)
probability_of_transmission = rand(1);
if probability_of_transmission > p
User(k,i) = 0;
else
User(k,i) = 1;
end
end
end
for k = 1:A
X = sum(User(k,:));
end
for k=1:A
idx = find(User(k,:)==1);
[a,b] = size(idx);
for i = 1:b
for j = 1:Trasmission_Time
User(k, (idx(i)+j-1)) = 1;
end
end
end
Y = sum(User);
%Creating row pairs to compare
row_pairs = nchoosek(1:size(User,1),2);
%disp(row_pairs);
n_pairs = size(row_pairs,1);
n_overlaps = zeros(n_pairs,1);
%Finding overlapping and counting them
for ii = 1:n_pairs
n_overlaps(ii,1) = nnz(User(row_pairs(ii,1),:) & User(row_pairs(ii,2),:));
if n_overlaps(ii,1) == 0
Zero_slot_overlapping = Zero_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 1
One_slot_overlapping = One_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 2
Two_slot_overlapping = Two_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 3
Three_slot_overlapping = Three_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 4
Four_slot_overlapping = Four_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 5
Five_slot_overlapping = Five_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 6
Six_slot_overlapping = Six_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 7
Seven_slot_overlapping = Seven_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 8
Eight_slot_overlapping = Eight_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 9
Nine_slot_overlapping = Nine_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 10
Ten_slot_overlapping = Ten_slot_overlapping + 1;
elseif n_overlaps(ii,1) == 11
Ten_slot_overlapping = Ten_slot_overlapping + 1;
One_slot_overlapping = One_slot_overlapping + 1;
end
end
disp([row_pairs n_overlaps]);
B = ([Zero_slot_overlapping; One_slot_overlapping; Two_slot_overlapping; Three_slot_overlapping; Four_slot_overlapping; Five_slot_overlapping; Six_slot_overlapping; Seven_slot_overlapping; Eight_slot_overlapping; Nine_slot_overlapping; Ten_slot_overlapping;] );
T = num2cell(B);
[Zero_slot_overlapping, One_slot_overlapping, Two_slot_overlapping, Three_slot_overlapping, Four_slot_overlapping, Five_slot_overlapping, Six_slot_overlapping, Seven_slot_overlapping, Eight_slot_overlapping, Nine_slot_overlapping, Ten_slot_overlapping] = deal(T{:})
figure(1)
plot(B,'--b');
%legend('10 Users')
legend('10 Users')
xlabel('No of colission');
ylabel('No of times');
axis([0 10 0 10]);
title('Plot for fix packet size with different no. of Users')
grid;
If you run this the plot is like this
0 comentarios
Respuesta aceptada
Star Strider
el 12 de Ag. de 2022
I am not certain what the problem is. Using plot with only one argument plots the argument with respect to the indices of the argument array. In MATLAB, indices begin with 1, not 0. Provide an independent variable vector as the first argument to plot it against that argument —
x = 0:9;
y = randn(size(x));
figure
subplot(1,2,1)
plot(y)
grid
title('One Argument')
subplot(1,2,2)
plot(x,y)
grid
title('Two Arguments')
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!