Search code examples
arraysstringmatlabcell

How to convert cell array of string numbers into numerical vector


I am using Matlab and I have the following data:

a = {'3' '11' '7'}; % This is what I have.

My goal is to use a function to convert such cell into a vector having the following shape:

b = [3 11 7]; % What I need to get!

If I try to use the b = cell2mat(a) function the result that I get is this number: b = 3117; which is not what I want.

What function should I use to reach my goal? If possible please do not use for loops but just Matlab functions.


Solution

  • You're looking for str2double:

    b = str2double(a);