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

조회 수: 6 (최근 30일)
Oscar Zampi
Oscar Zampi 2021년 3월 12일
댓글: Star Strider 2021년 3월 12일
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
Jan
Jan 2021년 3월 12일
What is the value of "Q"?
Oscar Zampi
Oscar Zampi 2021년 3월 12일
Hi, apologies for not replying to this message, I have inly just seen it. Q is 20.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2021년 3월 12일
편집: Jan 2021년 3월 12일
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
Oscar Zampi
Oscar Zampi 2021년 3월 12일
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.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2021년 3월 12일
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
Oscar Zampi
Oscar Zampi 2021년 3월 12일
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.
Star Strider
Star Strider 2021년 3월 12일
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?

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by