How do i get the matrix to be the same size. I cannot get the plot to mput any values.

 Accepted Answer

h=1:100;
That creates h as a vector.
for h=1:length(h)
length() of the vector is calculated first and recorded. Then variable h is overwritten with a succession of scalar values, 1, 2, 3, to 100. Afterwards variable h is left as the last thing it was assigned, which would be the scalar 100.
This kind of problem arises when you use the same variable name for two different purposes. You need to decide whether you want h to be a scalar or a vector. If you want it to be a vector then your for loop should iterate over the indices of the vector and you should pull out values from the vector
for idx=1:length(h)
H=h(idx) ;
rtot(idx) = 2/H + L/kg;
and so on.

3 Comments

How should the for loop be formatted for the other calculations? Im new to MATLAB and am just getting lost in the syntax getting dimensions to agree
Each left side your h is acting as an index, so use the index variable idx in each case on the left.
Each right side h appears to be there for its value so use the indexed value H in place of h on the right.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!