如何将字符串数字元胞数组转换为数值向量

How to convert cell array of string numbers into numerical vector

我正在使用 Matlab,我有以下数据:

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

我的目标是使用函数将此类单元格转换为具有以下形状的向量:

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

如果我尝试使用 b = cell2mat(a) 函数,我得到的结果是这个数字:b = 3117; 这不是我想要的。

我应该使用什么功能来达到我的目标?如果可能请不要使用 for 循环而只使用 Matlab 函数。

您正在寻找 str2double:

b = str2double(a);