Merging files with different dimensions

Hi guys. I am quite new in Matlab and I have the following problem. Hope its not too stupid.. i have three different files. The first one contains the x value (10x6480), the second y (10x6480), the third T (10x213840). T is organised in loops and describes the temperatures for different water depths(33 in total):
0,10,20,30,50,75,100,125,150,200,250,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1750,2000,2500,3000,35000,4000,4500,5000,5500
Accordingly, the first 10x6480 values in T describe the temperature distribution for depth level '0' with the coordinates from x and y. The next 10x6480 T values describe the temperature distribution for depth level '10' again with the coordinates from etc. What I would like to have is a file comprising x-y-depth-T.
x1-y1-depth1-T1
x2-y2-depth1-T2
x3-y3-depth1-T3
....
x1-y1-depth2-T64801
x2-y2-depth2-T64802
...
x1-y1-depth3-T129601
x2-y2-depth3-T129602
etc..
From my beginner skills, I would try to reshape the files into single column files. Then, I would copy x and y 33 times so that they have the same dimension as T. In the same way I would organise also the depth file so that I can merge at the end 4 different files with the same dimension. This 'solution' appears quite unsexy and I am sure that matlab is able to solve the problem with loops, somehow. I would be very happy for any help or link. :) Thanks a lot! P

2 Comments

Can you explain what is x1-y1-depth1-T1, their sizes?
PK
PK on 22 Jul 2015
Edited: PK on 22 Jul 2015
no, i wanted to illustrate the structure of the output file i would like to produce. Again, the T file comprises in total 213840 lines with 10 entries per line.
The first 64800 data values (or 6480 lines) constitute the temperature for the first water depth level @ 0 meters. The corresponding x (longitude) and y (latitude) are found in the x and y file, respectively. the x and y files both comprise exactly 64800 values.
The next 64800 data values in the T file show the temperature distribution for depth = 10 meters. Again, the x and y must be taken from the respective x and y file.
The next 64800 data values in T file show the temperature for the depth = 20 meters. x and y, again from the respective file.
At the end, I would like to produce an ascii file which comprises for each T value the correct depth and the corresponding x and y value from the respective file. Its obviiously a bit complicated to describe the problem. :) Sorry for any inconvenience.

Answers (2)

You can reshape T into a 3D matrix of size 10x 6480x 33:
T = reshape(T, 10, 6480, 33);

1 Comment

Thanks for your answer. At the end I want to have a single file which is organised in x-y-depth-T. Not really sure whether I got your point..
PK
PK on 22 Jul 2015
Okay, I solved it now in a way that I replicated (repmat) X Y and depth with 33. Now all the files have the same dimension as T and I only needed to export them in one file (dlmwrite).

This question is closed.

Products

Asked:

PK
on 22 Jul 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!