How to reshape coordinate geography

I want to know on how to reshape geographyc data from 100 x2 mtrix size into 4X25. Is there any one can help me to reshape my data into 4 x 25 matriks data?
Here is my data.
73.5 42.65
73.55 42.65
73.6 42.65
73.65 42.65
73.7 42.65
73.75 42.65
73.8 42.65
73.85 42.65
73.9 42.65
73.95 42.65
74 42.65
74.05 42.65
74.1 42.65
74.15 42.65
74.2 42.65
74.25 42.65
74.3 42.65
74.35 42.65
74.4 42.65
74.45 42.65
74.5 42.65
74.55 42.65
74.6 42.65
74.65 42.65
74.7 42.65
74.75 42.65
74.8 42.65
74.85 42.65
74.9 42.65
74.95 42.65
75 42.65
75.05 42.65
75.1 42.65
75.15 42.65
75.2 42.65
75.25 42.65
75.3 42.65
75.35 42.65
75.4 4 2.65
75.45 42.65
75.5 42.65
75.55 42.65
75.6 42.65
75.65 42.65
75.7 42.65
75.75 42.65
75.8 42.65
75.85 42.65
75.9 42.65
75.95 42.65
76 42.65
76.05 42.65
76.1 42.65
76.15 42.65
76.2 42.65
76.25 42.65
76.3 42.65
76.35 42.65
76.4 42.65
76.45 42.65
76.5 42.65
76.55 42.65
76.6 42.65
76.65 42.65
76.7 42.65
76.75 42.65
76.8 42.65
76.85 42.65
76.9 42.65
76.95 42.65
77 42.65
77.05 42.65
77.1 42.65
77.15 42.65
77.2 42.65
77.25 42.65
77.3 42.65
77.35 42.65
77.4 42.65
77.45 42.65
77.5 42.65
77.55 42.65
77.6 42.65
77.65 42.65
77.7 42.65
77.75 42.65
77.8 42.65
77.85 42.65
77.9 42.65
77.95 42.65
78 42.65
78.05 42.65
78.1 42.65
78.15 42.65
78.2 42.65
78.25 42.65
78.3 42.65
78.35 42.65
78.4 42.65
78.45 42.65

7 comentarios

Adam Danz
Adam Danz el 8 de Abr. de 2019
Editada: Adam Danz el 8 de Abr. de 2019
If your data are [100x2] then you have 200 elements. How do you put 200 elements in a [4x25] matrix (containing 100 elements)?
One method is if the 4x25 matrix is actually a cell array where each element contains (1x2) vector. Is that what you want to do?
Skydriver
Skydriver el 8 de Abr. de 2019
Yes I was a mistake. I want to reshape in a matrix of (4x50).
Skydriver
Skydriver el 8 de Abr. de 2019
Because it should be one pair of coordinate such as 73.5 42.65, 73.55 42.65, 73.6 42.65 etc
Adam Danz
Adam Danz el 8 de Abr. de 2019
Editada: Adam Danz el 8 de Abr. de 2019
There are a few ways to reshape your matrix.
If your original matrix where this
1a 1b
2a 2b
3a 3b
4a 4b
5a 5b
6a 6b
how would it look rearranged?
I want to re arranged for instance
1a(73.5) 1b(42.65), 2a(73.55) 2b(42.65), 3a(73.6) 3b(42.65 )
4a(73.65) 4b(42.65 ), 5a(73.7) 5b(42.65), 6a(73.75) 6b(42.65)
You ask for a 4x25 matrix, yet when you give us the desired shape you show a 2x6 matrix.
So, we still have absolutely no idea what you want. Do you want
1a 5a 1b 5b
2a 6a 2b 6b
3a 7a 3b 7b
4a 8a 4b 8b
or
1a 1b 2a 2b
3a 3b 4a 4b
5a 5b 6a 6b
7a 7b 8a 8b
or something else entirely?
Skydriver
Skydriver el 8 de Abr. de 2019
The second one iw oud be preffer to do it

Iniciar sesión para comentar.

Respuestas (2)

madhan ravi
madhan ravi el 8 de Abr. de 2019
Editada: madhan ravi el 8 de Abr. de 2019
Not sure which orientation you want but adapt which one suits you the best from the below:
reshape(data.',4,[]).' % this suits your comment
reshape(data.',4,[])
reshape(data,[],4).'
reshape(data,4,[])

5 comentarios

Skydriver
Skydriver el 8 de Abr. de 2019
It is not the wright anwer which is I want to do. Because it still read the lat first after that Lon. I need a pair of every coordinate lat1 lon1, lat2 lon2, lat3 lon3,...,lat50 lon50,
lat51 lon51,lat52 lon52,... lat100 lon100,
.................................................,lat200 lon200
madhan ravi
madhan ravi el 8 de Abr. de 2019
Editada: madhan ravi el 8 de Abr. de 2019
What? Perhaps:
reshape(data.',1,[]) % ? can't read your mind after this
Perhaps,
reshape(yourmatrix.', [], 4).'
is what is desired
Skydriver
Skydriver el 8 de Abr. de 2019
Editada: madhan ravi el 11 de Abr. de 2019
Thank you Guillaume it done to re arrange lat and lon.
Great
Skydriver
Skydriver el 8 de Abr. de 2019
Dear Guillaume let me ask simple question, how to add/insert a comma in between two pair of lat and lon.
lat1 lon1,lat2 lon2, lat3 lon3,...,lat50lon50

Iniciar sesión para comentar.

Adam Danz
Adam Danz el 8 de Abr. de 2019
Here you go
reshape(data.', 50,4).'

12 comentarios

Adam Danz
Adam Danz el 8 de Abr. de 2019
Same as Guillaume's comment (which I saw after responding here).
Skydriver
Skydriver el 8 de Abr. de 2019
Thank you Adam Danz, and I have small question. how to insert komma (,) between a pair of lat lon. lat1 lon1,lat2 lon2,lat3 lon3
Adam Danz
Adam Danz el 8 de Abr. de 2019
If you want to use a matrix, there is no way to do that. You could convert your matrix to text and insert a comma but there's little utility in doing so and you will no longer be able to perform mathematical operations on your data without converting it back to numeric format.
What is your final goal? If that's clearer to me I might be able to recommend an alternative.
Skydriver
Skydriver el 8 de Abr. de 2019
Yes off course, because in the next step I will use another that need a separate format by a comma sign.
Adam Danz
Adam Danz el 8 de Abr. de 2019
Editada: Adam Danz el 8 de Abr. de 2019
Without knowing the final goal, I can't make specific recommendations. The lines below convert the matrix to a cell array of stings which will help you get started.
dataCell = strsplit(sprintf('%.2f %.2f, |', data'),'|');
dataCell = reshape(dataCell(1:end-1), 4, 25);
The result...
4×25 cell array
Columns 1 through 6
{'73.50 42.65, '} {'73.70 42.65, '} {'73.90 42.65, '} {'74.10 42.65, '} {'74.30 42.65, '} {'74.50 42.65, '}
{'73.55 42.65, '} {'73.75 42.65, '} {'73.95 42.65, '} {'74.15 42.65, '} {'74.35 42.65, '} {'74.55 42.65, '}
{'73.60 42.65, '} {'73.80 42.65, '} {'74.00 42.65, '} {'74.20 42.65, '} {'74.40 42.65, '} {'74.60 42.65, '}
{'73.65 42.65, '} {'73.85 42.65, '} {'74.05 42.65, '} {'74.25 42.65, '} {'74.45 42.65, '} {'74.65 42.65, '}
You could combine the rows like this
[strcat(dataCell{1,:}); strcat(dataCell{2,:}); strcat(dataCell{3,:}); strcat(dataCell{4,:})]
The result...
ans =
4×300 char array
'73.50 42.65,73.70 42.65,73.90 42.65,74.10 42.65,74.30 42.65,74.50 42.65,74.70 42.65,74.90 42.65,75.10 42.65,75.30 42.65,75.50 42.65,75.70 42.65,75.90 42.65,76.10 42.65,76.30 42.65,76.50 42.65,76.70 42.65,76.90 42.65,77.10 42.65,77.30 42.65,77.50 42.65,77.70 42.65,77.90 42.65,78.10 42.65,78.30 42.65,'
'73.55 42.65,73.75 42.65,73.95 42.65,74.15 42.65,74.35 42.65,74.55 42.65,74.75 42.65,74.95 42.65,75.15 42.65,75.35 42.65,75.55 42.65,75.75 42.65,75.95 42.65,76.15 42.65,76.35 42.65,76.55 42.65,76.75 42.65,76.95 42.65,77.15 42.65,77.35 42.65,77.55 42.65,77.75 42.65,77.95 42.65,78.15 42.65,78.35 42.65,'
'73.60 42.65,73.80 42.65,74.00 42.65,74.20 42.65,74.40 42.65,74.60 42.65,74.80 42.65,75.00 42.65,75.20 42.65,75.40 42.65,75.60 42.65,75.80 42.65,76.00 42.65,76.20 42.65,76.40 42.65,76.60 42.65,76.80 42.65,77.00 42.65,77.20 42.65,77.40 42.65,77.60 42.65,77.80 42.65,78.00 42.65,78.20 42.65,78.40 42.65,'
'73.65 42.65,73.85 42.65,74.05 42.65,74.25 42.65,74.45 42.65,74.65 42.65,74.85 42.65,75.05 42.65,75.25 42.65,75.45 42.65,75.65 42.65,75.85 42.65,76.05 42.65,76.25 42.65,76.45 42.65,76.65 42.65,76.85 42.65,77.05 42.65,77.25 42.65,77.45 42.65,77.65 42.65,77.85 42.65,78.05 42.65,78.25 42.65,78.45 42.65,'
Skydriver
Skydriver el 8 de Abr. de 2019
The last comment from you about dataCell=reshape(dataCell(1:end-1), 4, 25) is not working
Adam Danz
Adam Danz el 8 de Abr. de 2019
Acutally, the problem was that I converted to integer values but you need ~2 decimal places. I edited the first line and replaced %d with %.2f
Skydriver
Skydriver el 8 de Abr. de 2019
Thank you Adam Danz, it is working know, but I don't know why I can't write and save into a spesific file such as : save('NewCoordinate.txt','NewCoordinate','-ascii')
fid = fopen('NewCoordinate.txt', 'wt');
for K = 1 : size(NewCoordinate,1)
fprintf(fid, '%s\n', NewCoordinate(K,:));
end
fclose(fid);
@Akhmad , Walter's code above does the trick. "NewCoordinate" is this line of code
NewCoordinate = [strcat(dataCell{1,:}); strcat(dataCell{2,:}); strcat(dataCell{3,:}); strcat(dataCell{4,:})]
Skydriver
Skydriver el 8 de Abr. de 2019
Thank you Adam Danz and Walter's, my code has completly finished its jobs
Adam Danz
Adam Danz el 9 de Abr. de 2019
Editada: Adam Danz el 11 de Abr. de 2019
High five!

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 8 de Abr. de 2019

Editada:

el 11 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by