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

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];
end
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];
end
end

2 Comments

What is the value of "Q"?
Hi, apologies for not replying to this message, I have inly just seen it. Q is 20.

Sign in to comment.

Answers (2)

Jan
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

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.

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

9 Comments

Hi, thank you for responding. This appears to set the result of imag() to 0 for all values. It does, however, solve the input arguments issue.
My pleasure!
The input arguments issue was what you originally wanted help with.
If the result is 0 for all inputs, then either the inputs are pure real and do not have significant imaginary components, or so small that the existing format option prevents them from being displayed. Note that in MATLAB, if one element of a vector is complex, regardless of the magnitude of the imaginary element, the entire vector will be complex, and the real elements will have an imaginary component of 0.
Use a suitable format option to see the full results, for example:
format long e
.
Hi, I tried using format long e but this seems to leave all balues as 0 still
In that situation, they may all actually be 0.
I cannot run your code (‘Q’ is nowhere defined), however note that the round call will round the arguments to the nearest integer. I have no idea what that might be doing to your data, since I cannot run your code.
The code works pefectly fine wehn using one predefined set of Txx and Txy, i.e. without getting them from the matrix 'Points'. The issue arises when using the for loop to run the code for each row of the matrix, I am stunmped as to why it does not work. (Q is 20 for any future refernce).
What is the code you posted supposed to do?
It reads the index value of a map in whcih the elevation is equated toi the colour. So by using imag to return the index value of a pixel, the elevation can be returend. The matrix contains one set of points that would be 'connected' to Rxx and Rxy. The first section calculates the coordinates of 20 points between Rxx and Rxy and points(:,1) and points(:,2).
The section that seems to be failing is designed to return the elevation of said 20 points in betwetween and put them into a 1X20 matrix for further use.
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.

Tags

Asked:

on 12 Mar 2021

Commented:

on 12 Mar 2021

Community Treasure Hunt

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

Start Hunting!