Arragement of vectors and matrix in text file

5 views (last 30 days)
I have 2D array of matrix(in excel or text file). This file contains GP height for my study area. 1st column of this file is latitude values and 1st row of this file is longitude values. Now corresponding to these latitude and longitude values there are GP_height values.
Please see that, from (2 row , 2colum) to (2,17) are values of GP_Height on the geographic position whose latitude are fixed (as 1st column) and longitude vary (along row values).
There are such trend in the each row and column.Actually this is 2D array.
Now i want to make a file (text or excel which will suited for the helper of my problem) in which 1st column consist on latitude value(which was fixed in my above explanations) corresponding to each longitude values in the 2nd column and third column will be their corresponding GP_Height.
This file( in excel and text) has been attach with new modifications.
For the batter understanding of my required output see my sample output my comment below.
Thanks in advance for assistance
  2 Comments
Muhammad Usman Saleem
Muhammad Usman Saleem on 14 Sep 2015
Edited: Muhammad Usman Saleem on 15 Sep 2015
Please see this output. Please suggest me also i have a lot of such data in text file. Which format will better for me for processing(actually time saving perceptive) excel or text?
Also not confuse with this file as it has been prepare from other data not from the share data..
Regards
latitude longitude GP_value
22.500 60.500 16511.000
22.500 61.500 16531.000
22.500 62.500 16532.000
22.500 63.500 16533.000
22.500 64.500 16536.000
22.500 65.500 16530.000
22.500 66.500 16532.000
22.500 67.500 16530.000
22.500 68.500 16526.000
22.500 69.500 16544.000
22.500 70.500 16538.000
22.500 71.500 16498.000
22.500 72.500 16520.000
22.500 73.500 16520.000
22.500 74.500 16509.000
22.500 75.500 16464.000
22.500 76.500 16476.000
22.500 77.500 16489.000
22.500 78.500 16477.000
23.500 60.500 16516.000
23.500 61.500 16514.000
23.500 62.500 16524.000
23.500 63.500 16529.000
23.500 64.500 16526.000
23.500 65.500 16522.000
23.500 66.500 16518.000
23.500 67.500 16510.000
23.500 68.500 16533.000
23.500 69.500 16502.000
23.500 70.500 16501.000
23.500 71.500 16508.000
23.500 72.500 16516.000
23.500 73.500 16495.000
23.500 74.500 16469.000
23.500 75.500 16468.000
23.500 76.500 16455.000
23.500 77.500 16466.000
23.500 78.500 16462.000
24.500 60.500 16490.000
24.500 61.500 16501.000
24.500 62.500 16512.000
24.500 63.500 16508.000
24.500 64.500 16512.000
24.500 65.500 16513.000
24.500 66.500 16508.000
24.500 67.500 16508.000
24.500 68.500 16502.000
24.500 69.500 16511.000
24.500 70.500 16468.000
24.500 71.500 16493.000
24.500 72.500 16492.000
24.500 73.500 16470.000
24.500 74.500 16479.000
24.500 75.500 16478.000
24.500 76.500 16476.000
24.500 77.500 16487.000
24.500 78.500 16479.000
25.500 60.500 16457.000
25.500 61.500 16471.000
25.500 62.500 16486.000
25.500 63.500 16496.000
25.500 64.500 16485.000
25.500 65.500 16477.000
25.500 66.500 16501.000
25.500 67.500 16501.000
25.500 68.500 16480.000
25.500 69.500 16483.000
25.500 70.500 16505.000
25.500 71.500 16473.000
25.500 72.500 16482.000
25.500 73.500 16467.000
25.500 74.500 16501.000
25.500 75.500 16474.000
25.500 76.500 16482.000
25.500 77.500 16474.000
25.500 78.500 16481.000
26.500 60.500 16439.000
26.500 61.500 16445.000
26.500 62.500 16459.000
26.500 63.500 16458.000
26.500 64.500 16474.000
26.500 65.500 16468.000
26.500 66.500 16474.000
26.500 67.500 16464.000
26.500 68.500 16456.000
26.500 69.500 16454.000
26.500 70.500 16469.000
26.500 71.500 16443.000
26.500 72.500 16474.000
26.500 73.500 16423.000
26.500 74.500 16450.000
26.500 75.500 16471.000
26.500 76.500 16455.000
26.500 77.500 16480.000
26.500 78.500 16477.000
27.500 60.500 16419.000
27.500 61.500 16446.000
27.500 62.500 16446.000
27.500 63.500 16424.000
27.500 64.500 16439.000
27.500 65.500 16459.000
27.500 66.500 16469.000
27.500 67.500 16460.000
27.500 68.500 16436.000
27.500 69.500 16441.000
27.500 70.500 16449.000
27.500 71.500 16417.000
27.500 72.500 16433.000
27.500 73.500 16479.000
27.500 74.500 16508.000
27.500 75.500 16473.000
27.500 76.500 16466.000
27.500 77.500 16477.000
27.500 78.500 16472.000
28.500 60.500 16407.000
28.500 61.500 16430.000
28.500 62.500 16374.000
28.500 63.500 16393.000
28.500 64.500 16406.000
28.500 65.500 16437.000
28.500 66.500 16456.000
28.500 67.500 16454.000
28.500 68.500 16437.000
28.500 69.500 16409.000
28.500 70.500 16421.000
28.500 71.500 16416.000
28.500 72.500 16417.000
28.500 73.500 16428.000
28.500 74.500 16448.000
28.500 75.500 16459.000
28.500 76.500 16465.000
28.500 77.500 16452.000
28.500 78.500 16457.000
29.500 60.500 16401.000
29.500 61.500 16411.000
29.500 62.500 16395.000
29.500 63.500 16391.000
29.500 64.500 16386.000
29.500 65.500 16407.000
29.500 66.500 16429.000
29.500 67.500 16444.000
29.500 68.500 16435.000
29.500 69.500 16436.000
29.500 70.500 16420.000
29.500 71.500 16416.000
29.500 72.500 16416.000
29.500 73.500 16401.000
29.500 74.500 16418.000
29.500 75.500 16419.000
29.500 76.500 16444.000
29.500 77.500 16454.000
29.500 78.500 16452.000
30.500 60.500 16364.000
30.500 61.500 16366.000
30.500 62.500 16395.000
30.500 63.500 16400.000
30.500 64.500 16377.000
30.500 65.500 16387.000
30.500 66.500 16410.000
30.500 67.500 16414.000
30.500 68.500 16427.000
30.500 69.500 16425.000
30.500 70.500 16423.000
30.500 71.500 16405.000
30.500 72.500 16419.000
30.500 73.500 16421.000
30.500 74.500 16420.000
30.500 75.500 16413.000
30.500 76.500 16432.000
30.500 77.500 16464.000
30.500 78.500 16521.000
31.500 60.500 16338.000
31.500 61.500 16334.000
31.500 62.500 16355.000
31.500 63.500 16367.000
31.500 64.500 16369.000
31.500 65.500 16366.000
31.500 66.500 16388.000
31.500 67.500 16393.000
31.500 68.500 16390.000
31.500 69.500 16404.000
31.500 70.500 16393.000
31.500 71.500 16384.000
31.500 72.500 16402.000
31.500 73.500 16401.000
31.500 74.500 16410.000
31.500 75.500 16418.000
31.500 76.500 16451.000
31.500 77.500 16477.000
31.500 78.500 16467.000
32.500 60.500 16354.000
32.500 61.500 16340.000
32.500 62.500 16344.000
32.500 63.500 16352.000
32.500 64.500 16360.000
32.500 65.500 16359.000
32.500 66.500 16380.000
32.500 67.500 16380.000
32.500 68.500 16375.000
32.500 69.500 16389.000
32.500 70.500 16381.000
32.500 71.500 16382.000
32.500 72.500 16381.000
32.500 73.500 16394.000
32.500 74.500 16396.000
32.500 75.500 16423.000
32.500 76.500 16476.000
32.500 77.500 16454.000
32.500 78.500 16405.000
33.500 60.500 16336.000
33.500 61.500 16331.000
33.500 62.500 16336.000
33.500 63.500 16334.000
33.500 64.500 16329.000
33.500 65.500 16334.000
33.500 66.500 16343.000
33.500 67.500 16349.000
33.500 68.500 16359.000
33.500 69.500 16375.000
33.500 70.500 16374.000
33.500 71.500 16388.000
33.500 72.500 16367.000
33.500 73.500 16387.000
33.500 74.500 16399.000
33.500 75.500 16450.000
33.500 76.500 16398.000
33.500 77.500 16382.000
33.500 78.500 16404.000
34.500 60.500 16308.000
34.500 61.500 16313.000
34.500 62.500 16320.000
34.500 63.500 16317.000
34.500 64.500 16311.000
34.500 65.500 16310.000
34.500 66.500 16309.000
34.500 67.500 16323.000
34.500 68.500 16340.000
34.500 69.500 16354.000
34.500 70.500 16373.000
34.500 71.500 16383.000
34.500 72.500 16374.000
34.500 73.500 16394.000
34.500 74.500 16395.000
34.500 75.500 16397.000
34.500 76.500 16382.000
34.500 77.500 16383.000
34.500 78.500 16389.000
35.500 60.500 16271.000
35.500 61.500 16285.000
35.500 62.500 16285.000
35.500 63.500 16299.000
35.500 64.500 16313.000
35.500 65.500 16315.000
35.500 66.500 16317.000
35.500 67.500 16319.000
35.500 68.500 16323.000
35.500 69.500 16357.000
35.500 70.500 16374.000
35.500 71.500 16382.000
35.500 72.500 16392.000
35.500 73.500 16364.000
35.500 74.500 16344.000
35.500 75.500 16366.000
35.500 76.500 16357.000
35.500 77.500 16369.000
35.500 78.500 16361.000
36.500 60.500 16261.000
36.500 61.500 16260.000
36.500 62.500 16266.000
36.500 63.500 16267.000
36.500 64.500 16287.000
36.500 65.500 16288.000
36.500 66.500 16296.000
36.500 67.500 16314.000
36.500 68.500 16305.000
36.500 69.500 16342.000
36.500 70.500 16344.000
36.500 71.500 16340.000
36.500 72.500 16327.000
36.500 73.500 16335.000
36.500 74.500 16335.000
36.500 75.500 16329.000
36.500 76.500 16351.000
36.500 77.500 16372.000
36.500 78.500 16386.000
37.500 60.500 16241.000
37.500 61.500 16246.000
37.500 62.500 16246.000
37.500 63.500 16242.000
37.500 64.500 16251.000
37.500 65.500 16258.000
37.500 66.500 16262.000
37.500 67.500 16281.000
37.500 68.500 16284.000
37.500 69.500 16295.000
37.500 70.500 16323.000
37.500 71.500 16289.000
37.500 72.500 16287.000
37.500 73.500 16308.000
37.500 74.500 16301.000
37.500 75.500 16328.000
37.500 76.500 16340.000
37.500 77.500 16339.000
37.500 78.500 16276.000
38.500 60.500 16213.000
38.500 61.500 16222.000
38.500 62.500 16231.000
38.500 63.500 16224.000
38.500 64.500 16226.000
38.500 65.500 16229.000
38.500 66.500 16264.000
38.500 67.500 16288.000
38.500 68.500 16297.000
38.500 69.500 16301.000
38.500 70.500 16304.000
38.500 71.500 16293.000
38.500 72.500 16270.000
38.500 73.500 16273.000
38.500 74.500 16291.000
38.500 75.500 16327.000
38.500 76.500 16323.000
38.500 77.500 16279.000
38.500 78.500 16225.000
Muhammad Usman Saleem
Muhammad Usman Saleem on 14 Sep 2015
Edited: Muhammad Usman Saleem on 15 Sep 2015
@dpi? please see my edited question again. This explain the problem better...

Sign in to comment.

Accepted Answer

Cedric
Cedric on 14 Sep 2015
Edited: Cedric on 14 Sep 2015
It's difficult to understand how your data must be processed because the various parts of your example do not match (values, sizes, etc), and the explanations are a bit convoluted.
So let's start with an example based on what I understood and we can discuss further from there:
% - Read source file.
fSpec = ['GPHeight_A[%f][%f]', repmat( ', %f', 1, 20 )] ;
data = textscan( fileread( 'Forward file.txt' ), fSpec ) ;
% - Get pressure from lookup table of pressures and first z+1 (indexing in
% MATLAB starts at 1). Update the code if z can vary within an input file.
pressures = 1000 : -100 : 100 ; % To adjust to your setting.
pressure = pressures(data{1}(1)+1) ;
% - Extract/aggregate data.
latId = data{2} + 1 ; % x + 1
GP = horzcat( data{3:end} ) ;
% - Define latitudes (based on ID? can vary among files?) and
% longitudes (fixed?).
lat = linspace( 22.5, 42.5, numel( latId )) ; % To adjust to your setting.
lon = linspace( 60.5, 78.5, size( GP, 2 )) ; % To adjust to your setting.
% - Build arrays of lon/lat which correspond to GP.
[LON, LAT] = meshgrid( lon, lat(latId) ) ;
% - Build output data: start by building 3 columns giving priority
% to same lats, and then transpose so it is well shaped for FPRINTF.
data = [reshape(LAT.',[],1), reshape(LON.',[],1), reshape(GP.',[],1)].' ;
% - Export: build file name based on pressure, 'prepend' header.
fId = fopen( sprintf( 'Output_%dhpa.txt', pressure ), 'w' ) ;
fprintf( fId, 'latitude\tlongitude\tGP_value\n' ) ;
fprintf( fId, '%.3f\t%.3f\t%.3f\n', data(:) ) ;
fclose( fId ) ;
See if you understand, and you will certainly have to modify the order/length/values of lon/lat, the direction of data, etc, but this is a starting point.
  35 Comments
Muhammad Usman Saleem
Muhammad Usman Saleem on 6 Apr 2016
Edited: Walter Roberson on 6 Apr 2016
If you guide me more then , i shall be very thankful to you.
I have saved this code as sorted_lat_split.m into drive of address
E:\meta data\new\data _thesis\NCEP\winds_speed
In winds_speed folder there are further 30 folders and in each of these 30 folder there are 12 folders inside. I want to past this 'sorted_lat_split.m' file in each of 12 folders and want to run this in each folder.
Tell me is this possible to paste this code so that my time will be save?

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!