from cell array to numeric vector
27 ビュー (過去 30 日間)
古いコメントを表示
I have a 1x52 length cell array of years stored in MWDIData_years, i need to get these to be a nummeric vector. I am trying something like
x = cell2mat(MWDIData_years(:));
But it gives me a 52x4 matrix of chars where each adress in the matrix is a single number, ie 1994 becomes 1 9 9 4.
How can i get around this problem ?
Thank you
Thor
0 件のコメント
採用された回答
Mark Whirdy
2012 年 12 月 16 日
編集済み: Mark Whirdy
2012 年 12 月 16 日
MWDIData_pop(1,1:5) = {[3752373],[3876616],[4006236],[4140773],[4279524]}; % square brackets in a cellarray indicates that the elements are numeric so if this is your starting point then no need to convert to a numeric, just convert cell to mat
cell2mat(MWDIData_pop(i,:)); % just a cell2mat
If I'm misunderstanding what you're doing here, then please paste in more of your code which GENERATES these cellarrays as the extra bit of clarity there will help in giving you a better response in how to manipulate/convert them to other datatypes.
その他の回答 (1 件)
Mark Whirdy
2012 年 12 月 16 日
yearCellArray = {'2008';'2009';'2010'};
yearVector = cellfun(@str2double,yearCellArray);
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!