フィルターのクリア

Convert very large nx1 cell into matrix mx3 matrix

2 ビュー (過去 30 日間)
Jon Smith
Jon Smith 2016 年 2 月 18 日
回答済み: Wolfgang 2016 年 2 月 18 日
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:

回答 (1 件)

Wolfgang
Wolfgang 2016 年 2 月 18 日
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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by