-1

I have one 5D data matrix containing values (:,:,1,1,1), (:,:,1,1,2),.....(:,:,1,1,10) with 57*92 elements each. I want to split this matrix into 10 matrices containing values (:,:,1,1,1) 57*92 in first matrix, (:,:,1,1,2) 57*92 in another matrix and so on. I am using Matlab.

The file looks as (have copied little part of it):

val(:,:,1,1,1) =

  Columns 1 through 11

      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
  14637      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0  14637  14637      0      0      0      0      0      0      0
  14638  14608  14621  14637  14637      0      0      0      0      0      0
  14653  14617  14608  14608      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0  14581  14581  14581      0
  14606  14606      0      0      0      0      0      0  14581  14581  14581
  14604  14606  14606      0      0      0      0      0      0      0      0
  14603  14606  14605  14596  14596      0      0      0      0      0      0
  14604  14604      0  14595  14596  14596      0      0      0      0      0
      0      0      0      0  14590  14590      0      0      0      0      0
      0      0  14598  14598  14597  14595  14594      0      0      0      0
      0      0      0  14598  14598  14587  14590      0      0      0      0
      0      0      0      0      0  14570  14570  14570      0      0      0
      0      0      0      0      0      0  14570  14570      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
  14627      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
      0      0      0      0      0      0      0      0      0      0      0
  14620      0      0      0      0      0      0      0      0      0      0
  14619  14620      0      0      0      0  14598  14598  14598      0      0
  14612  14611  14612      0      0      0      0  14598  14598  14598      0
  14613  14606  14607  14609      0      0      0      0      0      0      0
      0      0  14609  14609  14608  14599      0      0      0      0      0
  14581  14598  14601      0      0  14599  14599      0      0      0      0
  14581  14588  14601  14601      0  14581  14584  14587      0      0      0
  14586  14581  14597  14601  14591  14589  14575  14575      0      0      0
  14598      0      0      0  14590  14589  14589      0      0      0      0
  14597  14595  14580      0      0  14594  14594  14594      0      0      0
  14587  14581  14582  14580  14581  14582  14594  14594      0      0      0
  14615  14609  14593  14587  14583  14586  14592  14594      0      0      0
  14630  14633  14629  14602  14610  14628  14605  14602      0      0      0
  14645  14649  14650  14645  14640  14634  14630  14616  14610  14606  14593
  14659  14663  14667  14677  14642  14645  14642  14634  14607  14606      0
  14662  14662      0  14702  14702  14687  14649  14641  14621  14621      0
      0      0      0      0  14689  14691  14667  14650  14627  14621  14621
  14646  14633  14640  14685  14681  14677  14679      0      0      0  14646
  14647  14635  14630  14660  14685  14667  14656  14634  14624  14624      0
  14602  14619  14619  14620  14643  14644  14640  14639  14623  14623      0
  14578  14567  14597  14601  14614  14643  14639  14636  14621  14619  14623
  14574  14568  14571  14583  14590      0      0      0  14592  14592  14593
  14575  14566  14564  14572  14576      0      0      0      0  14592  14592
  14576  14571  14560  14558      0      0      0      0      0      0      0
      0      0  14561  14560      0      0      0      0      0      0      0

  Columns 12 through 22
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • 3
    Why not just use indexing/slicing to get those slices : `val(:,:,:,:,1)`, `val(:,:,:,:,2)` ...`val(:,:,:,:,10)`? – Divakar Oct 12 '17 at 10:59
  • Based in your other question, are you splitting to save? If so, why not save in another format? – Guto Oct 12 '17 at 11:22
  • @Guto, yes i am splitting to save different files. I have tried to save in another format as discussed in my another question. – Vaishali Jain Oct 13 '17 at 07:15
  • @Divakar How to index them using a loop, As i want to save each val(:,:,:,:,1), val(:,:,:,:,2)...I am using this loop but getting only one variable in output **for i=1:10 M_i=lst10(:,:,:,:,i); end** – Vaishali Jain Oct 18 '17 at 10:10
  • @VaishaliJain Index into output with iterator : `M_i(i) =lst10(:,:,:,:,i);`? – Divakar Oct 18 '17 at 17:40

1 Answers1

-1

You can do this, it will create N matrices, with the naming scheme M_number, where number goes from 1 to N:

% Create dummy 5D matrix
val = zeros(57,92,1,1,10);

% Create N matrices
N = 10;
for i = 1:N
    eval(sprintf('M_%d = val(:,:,1,1,%d);', i, i));
end
XRR
  • 418
  • 4
  • 16