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

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

How about x and y? You have not specified where/ which line is error.
Thank you for asking that question. I found my error

Sign in to comment.

 Accepted Answer

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));

More Answers (0)

Categories

Find more on Phased Array System Toolbox 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!