Merge multiple cells into one cell array

6 次查看(过去 30 天)
I have a three different cell arrays for my DMS (degree, minute, second). I want to combine it into one cell into the DMS format (degree°minute'second"). The second(") data is a decimal number while degree and minutes are integers.
I have a data of like this:
Degrees (19x1) = 128
128 ......
Minutes (19x1) = 34
32....
Seconds (19x1)= 14.651
40.654
How can I combine this three cell arrays into a form such that:
128°34'14.651"
128°32'40.654"
this is what I want to be the result.

回答(1 个)

Chunru
Chunru 2024-4-12
编辑:Chunru 2024-4-12
n = 3;
Degrees = randi([0 359], [n, 1])
Degrees = 3x1
146 169 193
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Minutes = randi([0 59], [n, 1])
Minutes = 3x1
27 55 47
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Seconds = rand([n, 1])*60
Seconds = 3x1
34.2840 39.6742 12.0341
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
s = compose("%d%c%d%c%.4f%c", Degrees, char(176), Minutes, "'", Seconds, '"')
s = 3x1 string array
"146°27'34.2840"" "169°55'39.6742"" "193°47'12.0341""

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by