How to take x as a vector in for loop?
38 views (last 30 days)
for x=dx:length: nx+1
This code shows dimension error in
T_check = interp1(xts,pts,x,'linear');
because x is showing only one value here. Anyone please guide me how to correct x?
Eric on 7 Sep 2017
The variable x here is a for loop counter, which means it will iterate through the values given by dx:length:nx+1 and therefore only ever have one value at a time. If you want x to be the entire vector, set x=dx:length:nx+1 again on its own after the for loop.
Protip: You can set x before the for loop as well and change the iterator to
or something of that nature. Then you can index into x using x(i) and still have x as a vector and only look at a single value in x.
Protip: Use ctrl-i for proper indenting, as Stephen described in his comment. It really does make reading code easier for both you and us on MATLAB Answers.
Protip: Do not use MATLAB functions as variable names (e.g. length, count). Choose names like xlength or counter, even if you are not using the MATLAB functions. This way you will not override the MATLAB function now or in the future and will avoid any headaches that that may cause.