'Too many input arguments' error when using imag()
Show older comments
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
Answers (2)
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
on 12 Mar 2021
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.)
9 Comments
Oscar Zampi
on 12 Mar 2021
Edited: Oscar Zampi
on 12 Mar 2021
Star Strider
on 12 Mar 2021
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.
format long e
.
Oscar Zampi
on 12 Mar 2021
Star Strider
on 12 Mar 2021
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.
Oscar Zampi
on 12 Mar 2021
Star Strider
on 12 Mar 2021
What is the code you posted supposed to do?
Oscar Zampi
on 12 Mar 2021
Oscar Zampi
on 12 Mar 2021
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?
Categories
Find more on Image Arithmetic 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!