How to output a new matrix that swaps the position of the beginning and end of a separate matrix

2 views (last 30 days)
Liam on 5 Jul 2022
Commented: Liam on 11 Jul 2022
The project I'm currently working on involves the use of global data with latitudes and longitudes.
I'm extracting data for an area between 13degree W and 30degree E for the longitudinal values. However the data outputed has a linear matrix so 13degree W is actually stored as 347E
My current code is below which outputs the correct data between 347 - 360 followed by zeros for 0-30degrees since the matrix doesn't return to the beginning point.
My question is whether I can simply have matrix return to column 1 when the end of the matrix is met or whether I will need to output a new matrix that swaps their position first.
Thanks for any help you can provide!
for i=1:18
for j=1:43

Accepted Answer

Jan on 5 Jul 2022
latitude = zeros(1,18);
longitude = zeros(1,43);
for i=1:18
latitude(i) = 48+(i-1)*1;
for j=1:43
longitude(j) = mod(347+(j-1)*1, 360);
% Or without loops:
latitude = 48 + ((1:18) - 1)*1;
longitude = mod(347+((1:43) - 1)*1, 360);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by