필터 지우기
필터 지우기

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