Filter löschen
Filter löschen

Error in plotting a function, left and right side with diferent dimensions

1 Ansicht (letzte 30 Tage)
When I use this code:
format short
prod_total = zeros(1000, 1);
vet_pedidos = zeros(1000, 1);
x_exp = zeros(1000, 1);
vet_servido = zeros(1000, 1);
for j = 1:1000
a = rng_cheap;
x = a;
if (x <= 0.2)
prod = 1;
elseif (x > 0.2 && x <= 0.6)
prod = 2;
elseif (x > 0.6 && x <= 1)
prod = 3;
end
prod_total(j) = prod;
%
y = 2.8*a + 0.8;
y = y*10;
y = fix(y);
y = y/10;
vet_pedidos(j)= y;
%
x_exp(j) = a;
vet_servido(j) = - (1/2) * log(1- x_exp);
end
[xs, index] = sort(x_total);
ys = vet_total(index);
plot(xs, ys, '-x');
It gives me the following error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in enunciado8 (line 28)
vet_servido(j) = - (1/2) * log(1- x_exp);
Context: the rng_cheap gives a number.

Akzeptierte Antwort

Torsten
Torsten am 7 Mär. 2023
Verschoben: Torsten am 7 Mär. 2023
Most probably,
vet_servido(j) = - (1/2) * log(1- x_exp(j));
instead of
vet_servido(j) = - (1/2) * log(1- x_exp);

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by