My vectors appear to be the same length but I am still getting error for plot

3 次查看(过去 30 天)
Hi there, I am trying to do an iterative and random sampling best fit plot. I keep getting error, saying that "vectors must be the same length. My mat1 is 38 x 2, RP1 is 38 x 1 and Dmge is 38 x 1. Any suggestions
mat1 = [Dmge RP1];
for ii=1:10
b = randsample(1:38,35);
A= 5500; B=0.19; C=2.3;
goemp_fit1 = @(y)sum((y(1)*exp(-exp(-y(2)*(x(1,:)-y(3))))-x(2,:)).^2);
coeff = fminsearch(goemp_fit1,[A B C]);
A = coeff(1);
B = coeff(2);
C = coeff(3);
y2 = A*exp(-exp(-B*(RP1-C)));
y2_tp = transpose(y2);
plot(mat1(b,2),y2,'-','Color',mcolour(ii,:))
xlabel('Flow3');
ylabel('Damage ($000USD)');
title('Damage v Flow3');
end
  3 个评论
KSSV
KSSV 2018-9-14
编辑:KSSV 2018-9-14
How about x and y? You have not specified where/ which line is error.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-9-14
b = randsample(1:38,35);
is going to return a vector of length 35.
y2 = A*exp(-exp(-B*(RP1-C)));
with RP1 being a vector of length 38, is going to return a vector of length 38.
plot(mat1(b,2),y2,'-','Color',mcolour(ii,:))
is going to use the 35 values in b to index rows in mat1, giving you 35 results. But y2 is 38 values.
I would suggest that you replace
b = randsample(1:38,35);
with
b = randperm(size(mat1, 1), length(RP1));

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by