Convert matrix of char to numbers
2 次查看(过去 30 天)
显示 更早的评论
I have a big m*n matrix with char elements (the elements are natural numbers). I want to change it to a matrix to work with numbers. Using for-loop and str2num works, but I want to avoid for-loop and a fast and efficient way.
[m,n]=size(Matrix);
for i=1:n
str2num(Matrix(:,i));
end
Any help would be appreciated.
Thanks,
回答(1 个)
Azzi Abdelmalek
2016-3-28
v=['123';'456';'789';'456']
[n,m]=size(v)
w=str2double(mat2cell(v',ones(m,1),n))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!