'Too many input arguments' error when using imag()
조회 수: 6 (최근 30일)
이전 댓글 표시
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
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 = [];
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
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!