How to reshape coordinate geography
Mostrar comentarios más antiguos
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
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
el 8 de Abr. de 2019
Skydriver
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?
Skydriver
el 8 de Abr. de 2019
Guillaume
el 8 de Abr. de 2019
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
el 8 de Abr. de 2019
Respuestas (2)
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
el 8 de Abr. de 2019
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
Guillaume
el 8 de Abr. de 2019
Perhaps,
reshape(yourmatrix.', [], 4).'
is what is desired
Skydriver
el 8 de Abr. de 2019
Editada: madhan ravi
el 11 de Abr. de 2019
Skydriver
el 8 de Abr. de 2019
Adam Danz
el 8 de Abr. de 2019
Here you go
reshape(data.', 50,4).'
12 comentarios
Adam Danz
el 8 de Abr. de 2019
Same as Guillaume's comment (which I saw after responding here).
Skydriver
el 8 de Abr. de 2019
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
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
el 8 de Abr. de 2019
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
el 8 de Abr. de 2019
Walter Roberson
el 8 de Abr. de 2019
fid = fopen('NewCoordinate.txt', 'wt');
for K = 1 : size(NewCoordinate,1)
fprintf(fid, '%s\n', NewCoordinate(K,:));
end
fclose(fid);
Adam Danz
el 8 de Abr. de 2019
NewCoordinate = [strcat(dataCell{1,:}); strcat(dataCell{2,:}); strcat(dataCell{3,:}); strcat(dataCell{4,:})]
Skydriver
el 8 de Abr. de 2019
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!