I have used xlsread in order to read a spreadsheet as a two dimensional matrix but I need to read a spreadsheet in the form of
2,2 2,0
0,2 1,1
As a 2,2,2 matrix
Is there a way to use Matlab to separate the values of the cells or do I have to use two separate matrices in the spreadsheet
If the data in the spreadsheet is one number per cell, just import the data into a 2D array. The command 'reshape' can change the dimensionality of the array, but it's sometimes a little tricky to get things to reorder the way you want them. This code will take a 2D vector M of size Rx(2C) and turn it into a 3D data block of size [R C 2] alternating pages across the rows of the original. It's hard to tell with your numbers that it's working so I used a different set that's easier to keep track of.
Which results in:
If the data in the spreadsheet has two values per cell separated by a comma (as suggested in the comments), it will import into MATLAB as a series of cell arrays. Consider a spreadsheet with 4 cells (2x2) with the following data:
In MATLAB we can load this using
And variable TXT would be:
Operating on cells is a pain. I can't think of a way to do this without 'for' loops but once you're doing that, assigning to the third dimension is easy.
For the values above