Using the dms2degree Command Sequentially to Populate an Array using a Sub-routine
3 views (last 30 days)
Show older comments
How to I use the dms2degree (mapping toolbox) command for array elements using a for statement?
Eg.
n=6
A = [180 342 350 121 125 179; 0 54 41 16 23 59; 3 49 18 20 13 50]'
B (6,1) = zeros
for i =1:n
tempVal = dms2degree(A(i,1), (i,2), (i,3)) % Syntax error when trying to specify row & element of A
% Populates degree.decimals into array B iteratively
B(i,1) = tempVal
end
Thanks
0 Comments
Answers (2)
James Tursa
on 27 Jun 2019
Edited: James Tursa
on 27 Jun 2019
With a for-loop, you need to use A in all of your indexing and use the [ ] brackets to form a vector input (and spell the function name correctly). E.g.,
tempVal = dms2degrees([A(i,1), A(i,2), A(i,3)])
Or just
tempVal = dms2degrees(A(i,1:3))
Also, you need to pre-allocate B differently:
B = zeros(n,1);
But of course you can do the whole thing without a for-loop:
B = dms2degrees(A);
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!