Convert matrix of char to numbers
1 view (last 30 days)
Show older comments
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,
Answers (1)
Azzi Abdelmalek
on 28 Mar 2016
v=['123';'456';'789';'456']
[n,m]=size(v)
w=str2double(mat2cell(v',ones(m,1),n))
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!