MATLAB Answers

'Too many input arguments' error when using imag()

1 view (last 30 days)
Oscar Zampi
Oscar Zampi on 12 Mar 2021
Commented: Star Strider on 12 Mar 2021
Hi, I have a piece of code that takes an input matrix and runs each row through a series of for loops. I arrive at a 'too many input arguments' error when getting to the imag function. I assume it is because of the multiple for loops, but I cannot seem to get it working. I have incldue the snippet of code below, ny help would be appreciated.
Rxx = 721;
Rxy = 435;
points = [484 1207 52005; 485 1208 64693; 486 1208 65375;...
489 1205 40517; 491 1207 65533; 493 1206 62713;...
510 1205 45345; 606 1208 48405; 486 1206 44571; 491 1205 45657];
for Point = 1:10
Txy = points(Point,1);
Txx = points(Point,2);
x = [Txx Rxx];
y = [Txy Rxy];
N = 20;
xi = linspace(x(1), x(2), N+1);
yi = interp1(x, y, xi, 'linear');
countPointsAlongLine = 0 ;
PointsAlongLine = zeros([],2) ;
for P = 0:Q
PointPx = Txx + (P*(Rxx-Txx)/N);
PointPy = Txy +(P*(Rxy-Txy)/N);
SubPlotxPRound = round(PointPx);
SubPlotyPRound = round(PointPy);
format long
ElevPxRound = round(SubPlotxPRound);
ElevPyRound = round(SubPlotyPRound);
countPointsAlongLine = countPointsAlongLine+1 ;
PointsAlongLine(countPointsAlongLine,:) = [ElevPyRound ElevPxRound];
ElevationCount = 0 ;
ElevationMatrix = zeros([],1) ;
for PAL = 1:Q+1
ElevPointy = PointsAlongLine(PAL,1);
ElevPointx = PointsAlongLine(PAL,2);
Elevationcm = imag(ElevPointx,ElevPointy);
Elevationm = Elevationcm/100;
ElevationCount = ElevationCount+1 ;
ElevationMatrix(ElevationCount,:) = [Elevationm];
Oscar Zampi
Oscar Zampi on 12 Mar 2021
Hi, apologies for not replying to this message, I have inly just seen it. Q is 20.

Sign in to comment.

Answers (2)

Jan on 12 Mar 2021
Edited: Jan on 12 Mar 2021
imag accecpts 1 input onlky. I cannot guess, what "imag(ElevPointx,ElevPointy)" should do, therefore I cannot suggest a solution.
This is strange also:
ElevationMatrix(ElevationCount,:) = [Elevationm];
[ and ] is the operator for concatenation. With 1 argument only, it is concatenated with nothing and therefore this is a waste of time only.
Why do you have a "format long" inside the loops?
What is the purpose of: "ElevationMatrix = zeros([],1)"? Do you mean:
ElevationMatrix = [];
  1 Comment
Oscar Zampi
Oscar Zampi on 12 Mar 2021
Hi, thank you for getting back to me.
the 'format long' is to format the sections in the loop seperately to the rest of the fiel (this was a snippet of code from a larger file).
The "ElevationMatrix = zeros([],1)" was suggest to me by someone else, as it ables the results of the for loop to be stored into a matrix of row size 1.
ElevPointx and ElevPointy are x/y coordinates of a point, the point at which I wish to take the imag reading.

Sign in to comment.

Star Strider
Star Strider on 12 Mar 2021
Enclose the arguments in square brackets to create a vector from them:
Elevationcm = imag([ElevPointx,ElevPointy]);
That will work for individual elements and easily for column vectors for those variables. (It would also work for row vectors, although for row vectors the result would be a bit confusing.)
Star Strider
Star Strider on 12 Mar 2021
If all you want to do is to interpolate the values in the (10x3) ‘Points’ matrix, there are likely much easier ways to do it.
What do you want as the final result?

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!