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

1 次查看(过去 30 天)
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.

采纳的回答

Torsten
Torsten 2023-3-7
移动:Torsten 2023-3-7
Most probably,
vet_servido(j) = - (1/2) * log(1- x_exp(j));
instead of
vet_servido(j) = - (1/2) * log(1- x_exp);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Argument Definitions 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by