Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
accumulate 2D data to get 3D saved data fiel

Subject: accumulate 2D data to get 3D saved data fiel

From: edward kabanyas

Date: 4 Apr, 2012 13:30:19

Message: 1 of 6

Hi all !,

I have longitude-latitude (2D) data every one hour. I want to accumulate the hourly data into a file, thus I will have a file containing 3D data (time-longitude-latitude). If we save the hourly-longitude-latitude data directly we will get 2D only. Of course, we can open all files in the same time and then make 3D array. However, if we have several years of data, this procedure will take a lot of memory. Is there any idea to do it, for example by saving the file one by one, but the final saved file in 3D array ? From 3D data, I wan to make 3D contour (time (vertical/z axis) -longtitude (x-axis)-latitude (y-axis)).

Thanks for help.

Edward

Subject: accumulate 2D data to get 3D saved data fiel

From: edward kabanyas

Date: 5 Apr, 2012 23:21:28

Message: 2 of 6

Hi All,

Finally, i try the following trick:

% PH3D is 2D array (lat-long) -hourly file.

for jj=1:size(listfile,1)
.......

for j = 1:1:1
     for k =1:size(PH3D,1)
         for l = 1:1:size(PH3D,2) % latitude
             PH3Drev(j,k,l)=PH3D(k,l); % longitude
         end
     end
 end


dlmwrite(outfile1, PH3Drev, 'delimiter', '\t', 'precision', 6, '-append')
end

Tatget: for one day i have 24 files (24 hours). Then by accumulating the data with the above trick, I hope to get 3D array (time-lat-long).

Each file is assumed as 3D array as above. However, when I saved to ASCII (text) file and open again in matlab, the data is still 2D array. Any suggestion to save 3D array in text file ? I will read this text file by Fortran..

thank you..

Edward






"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <jlhidb$rqq$1@newscl01ah.mathworks.com>...
> Hi all !,
>
> I have longitude-latitude (2D) data every one hour. I want to accumulate the hourly data into a file, thus I will have a file containing 3D data (time-longitude-latitude). If we save the hourly-longitude-latitude data directly we will get 2D only. Of course, we can open all files in the same time and then make 3D array. However, if we have several years of data, this procedure will take a lot of memory. Is there any idea to do it, for example by saving the file one by one, but the final saved file in 3D array ? From 3D data, I wan to make 3D contour (time (vertical/z axis) -longtitude (x-axis)-latitude (y-axis)).
>
> Thanks for help.
>
> Edward

Subject: accumulate 2D data to get 3D saved data fiel

From: Bruno Luong

Date: 6 Apr, 2012 06:09:12

Message: 3 of 6

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message y. Any suggestion to save 3D array in text file ? I will read this text file by Fortran..

help save
help fopen
help fwrite

Bruno

Subject: accumulate 2D data to get 3D saved data fiel

From: edward kabanyas

Date: 6 Apr, 2012 06:28:23

Message: 4 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jlm1a8$fjf$1@newscl01ah.mathworks.com>...
> "edward kabanyas" <djuky_hmi@yahoo.com> wrote in message y. Any suggestion to save 3D array in text file ? I will read this text file by Fortran..

Thanks bruno for reply..


> help save

I tried to use save, however, it does not work because of 3D data ?
I use also the following:
dlmwrite(outfile1, PH3Drev, 'delimiter', '\t', 'precision', 6, '-append')

But when I load/read it again in matlab, it becomes 2D not 3D array..

> help fopen
> help fwrite
I think this for binary not for text file..

Edward


>
> Bruno

Subject: accumulate 2D data to get 3D saved data fiel

From: Bruno Luong

Date: 6 Apr, 2012 06:38:17

Message: 5 of 6

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <jlm2e7$j83$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jlm1a8$fjf$1@newscl01ah.mathworks.com>...
> > "edward kabanyas" <djuky_hmi@yahoo.com> wrote in message y. Any suggestion to save 3D array in text file ? I will read this text file by Fortran..
>
> Thanks bruno for reply..
>
>
> > help save
>
> I tried to use save, however, it does not work because of 3D data ?
> I use also the following:
> dlmwrite(outfile1, PH3Drev, 'delimiter', '\t', 'precision', 6, '-append')

save with -ascii option, but you need to formate your data before.

>
> But when I load/read it again in matlab, it becomes 2D not 3D array..
>
> > help fopen
> > help fwrite
> I think this for binary not for text file..
>

Right, for text use fprintf after fopen

Bruno

Subject: accumulate 2D data to get 3D saved data fiel

From: edward kabanyas

Date: 6 Apr, 2012 06:49:17

Message: 6 of 6

Thanks again Bruno for your reply.

> Right, for text use fprintf after fopen

I tried the following:

data = randn(4,3,2);

fileID = fopen('test.txt','w');
fprintf(fileID,'%12.8f\n',data);
fclose(fileID);

However, when I load it again into matlab:
>> load('test.txt');

data become 1x24 array not 4x3x2 as the original.

Regards,
Edward



 
> Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us