Effacer les filtres
Effacer les filtres

Convert very large nx1 cell into matrix mx3 matrix

2 vues (au cours des 30 derniers jours)
Jon Smith
Jon Smith le 18 Fév 2016
I have a large cell of size 190004x1. Each cell consists of a number, a decimal point (.), a minus sign (-) or a blank space.
I want to merge each cell element without a space between them into a single cell, whenever a space occurs I want to move to the cell on the right. Whenever a I have 2 spaces I want to start a new line. Here is an example:

Réponses (1)

Wolfgang
Wolfgang le 18 Fév 2016
Hi.
First: find out if all of your cell elements are of class type 'char'. Perhaps you have a mix of 'char' and 'double' / 'integer' elements.
If there are not only 'char' elements, you can fix this with:
% Convert all elements in your cell into type 'char'
% (only if you have mixed class types in your cell )
newCell = cellfun(@num2str, yourCell);
As result (newCell) you get a very long character array (string) of the size [nx1]; Now you can split the transposed character array at the delimiter (blank spaces) and convert it into double values
% split the transposed character array at the delimiter (blank spaces)
splittedStrings = strsplit(newCell',' ');
% convert the strings to double values
numbers = str2double(splittedStrings)
Now, you have long vector of numbers. Bring them into matrix form with the reshape command:
% reshape vector to matrix
yourMatix = reshape(numbers,[],3);
I hope this will help you

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by