My vectors appear to be the same length but I am still getting error for plot
1 view (last 30 days)
Show older comments
Naveed Hossain
on 14 Sep 2018
Commented: Naveed Hossain
on 15 Sep 2018
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 Comments
Accepted Answer
Walter Roberson
on 14 Sep 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!