degrees2dms Syntax
Show older comments
I have the following test code with an error thrown when trying to populate array C using the degrees2dms function:
% Array with original DMS (n x 3 array)
A = [180 342 350 121 125 179; 0 54 41 16 23 59; 3 49 18 20 13 50]'
% Array for Degrees.Decimal values (from array A)
B (6,1) = zeros
% Array for degrees2DMS repopulation
C (6,3) = zeros
%% Initial dms2degrees Array B Population
for i = 1:6
B(i,1) = dms2degrees([A(i,1), A(i,2), A(i,3)])
end
%% Subsequent degrees2dms Array C Population Attempt
for i = 1:6
degrees2dms([C(i,1),C(i,2),C(i,3)]) = B(i,1)
% Error Returned:
% Array indices must be positive integers or logical values.
%Error in Test2_Degrees2dms (line 31)
%degrees2dms([C(i,1),C(i,2),C(i,3)]) = B(i,1)
end
Why am I getting an error stating that negative indicies are being used when I have specified the numberic doman from 1 to 6?
1 Comment
Guillaume
on 1 Jul 2019
Justin's comment posted as an answer moved here:
I noticed (and have since ammended) the degree.decimal array being referenced for values in array C from array A to array B.
Inncorrect Attempt:
degrees2dms([C(i,1),C(i,2),C(i,3)]) = A(i,1)
Corrected Attempt:
degrees2dms([C(i,1),C(i,2),C(i,3)]) = B(i,1)
However, the returned error remains the same.
Array indices must be positive integers or logical values.
Error in Test2_Degrees2dms (line 32)
degrees2dms([C(i,1),C(i,2),C(i,3)]) = B(i,1)
Accepted Answer
More Answers (2)
Steven Lord
on 1 Jul 2019
What you've written:
degrees2dms([C(i,1),C(i,2),C(i,3)]) = A(i,1)
attempts to create a variable named degrees2dms and assign A(1,1) to an element of it. However, the indices you're using to assign into degrees2dms are all 0, which makes them invalid.
I'm not sure of what you intended this line to do, but if you try explaining it in words we may be able to help write the code to achieve your goal.
1 Comment
Chirag Nighut
on 1 Jul 2019
0 votes
Degrees2dms takes in degree input (1x1) and converts it into degree minute and second ie. 1x3 output. So here when you pass 1x3 input to your degrees2dms function you get a 3x3 output in return and now that cannot be assigned from A(i,1) and therefore the error.
If possible could you please let me know what your end target is and I can then try to help you out find a solution.
1 Comment
Categories
Find more on Environment and Settings 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!