arrays - Writing a 3D Matlab matrix to a file as 1D and read it back in C -


i have three-dimensional matlab matrix, shape 3x4x5 . want write matrix .txt file 1-dimensional , read out in c.

however, numbers written should x , y dimension first (so 4x5) followed z-dimension (3).

sample code filling matrix:

duneven = 1:3*4*5 duneven = reshape(duneven,[3 4 5]); 

i hoped effect permuting matrix this:

duneven = permute(duneven,[3 1 2]); 

and writing out this:

fp = fopen('testuneven.txt','w'); fprintf(fp,'%f ',duneven); fclose(fp); 

however, reading in c - this:

file* fp; fp = fopen("testuneven.txt","r");  for(int = 0; < 3*4*5;i++){    float var;    fscanf(fp,"%f ",&var);    printf("%f ",var); } fclose(fp); 

reading out in matlab gives same output. furthermore, cat-ing out file in shell gives same results. issue located in matlab code

does not give desired output. instead prints out first cols. how can fix issue?

i guess mixed order in permute() call. inital discription of desired dimension order stats 4x5 , 3

your code

duneven = 1:3*4*5 duneven = reshape(duneven,[3 4 5]); duneven = permute(duneven,[3 1 2]) 

produces 5x3x4.

consider using duneven = permute(duneven,[2 3 1])


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -