Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

Torsten
Torsten le 7 Mar 2023
Déplacé(e) : Torsten le 7 Mar 2023
Most probably,
vet_servido(j) = - (1/2) * log(1- x_exp(j));
instead of
vet_servido(j) = - (1/2) * log(1- x_exp);

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by