This has the same restriction, all the cell contents must have the same number of characters or the command will error. Simply convert them to a numeric array: Theme. Such data structures are ideal for many programs wed wish to write. I also have a logical array the length of p x 1. So as pointed at, if one of your cell contained Foo24 then the reshape command would error.Įdit: Or as Chris Luengo kindly mentionned in comment, a simpler command to get exactly the same result: > cell2mat(FooCellArray.') The numbers are stored as character arrays, the reason the dimensions did not match. MATLAB deals with vectors and matrices naturally. matlab - Select specific pages of 3D matrix with logic array - Stack Overflow Select specific pages of 3D matrix with logic array Ask Question Asked today Modified today Viewed 5 times 0 I have a 3D matrix n x m x p where p represents 1400 daily 2D data arrays. Convert array to cell array whose cells contain subarrays. Mainly because they are not as flexible as strings, each line has to have the same number of elements. This MATLAB function divides array A into smaller arrays and returns them in cell array C. This result type is a char array, which are ok when they are simple vector but they get quite unwieldy once they are in 2D. If you MATLAB version is older AND if all the strings in the cell array have the same length, you could convert your cell array into a 2D character array: > reshape(cell2mat(FooCellArray),4,).'įor this one, transposition wouldn't really make sense. Note the terminology of the result type, it is a string array. You can transpose it if you want it as a column instead of line vector. I would like to convert this cell into a 3 dimensional matrix of size 8x454x900. The benefit of this method is that it will work even if the strings contained in your cell array are not all of the same length. I have a cell that is 8x454 with each element in the cell containing a 900x1 matrix. Although MATLAB considers all stored data as matrices, it is convenient to think. You can directly use the function convertCharsToStrings: > convertCharsToStrings(FooCellArray) Answers (2) I would create a single cell array (vector) with the names. With a smaller starting example: FooCellArray =
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |