matlab将cell型变成double型
1、先把cell转变成char数组,在把他转变成数据类型.原理是转变成char之后的矩阵每行的长度是相同的.[plain] view plaincopystr2num(char(cdata))
2、使用cellfun函数,第一个参数传递对每个cell单元使用的函数名,第二个参数是cell名.[plain] viewplaincopycellfun(@str2num, cdata)
3、元胞数组的元素都是矩阵呀,转化完后也是矩阵。clear all;clc;test ={'1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4'};
for n=1:length(test)
x{n}=str2num(test{n});
end
x =
Columns 1 through 10
[1] [1] [1] [1] [2] [2] [2] [2] [3] [3]
Columns 11 through 16
[3] [3] [4] [4] [4] [4]
>> class(x{1})
ans
2023-08-15 广告
clear
all;clc;
test
=
{'1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4'};
for
n=1:length(test)
x{n}=str2num(test{n});
end
x
=
Columns
1
through
10
[1]
[1]
[1]
[1]
[2]
[2]
[2]
[2]
[3]
[3]
Columns
11
through
16
[3]
[3]
[4]
[4]
[4]
[4]
>>
class(x{1})
ans
=
double
---------------------------------------------------------
如果不想要元胞数组,可以加一句转化一下:
clear
all;clc;
test
=
{'1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4'};
for
n=1:length(test)
x{n}=str2num(test{n});
end
for
m=1:length(x)
y(m)=x{m}(1)
end
y
=
Columns
1
through
12
1
1
1
1
2
2
2
2
3
3
3
3
Columns
13
through
16
4
4
4
4
A =
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
clear all;clc;
test = {'1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4'};
for n=1:length(test)
x{n}=str2num(test{n});
end
x =
Columns 1 through 10
[1] [1] [1] [1] [2] [2] [2] [2] [3] [3]
Columns 11 through 16
[3] [3] [4] [4] [4] [4]
>> class(x{1})
ans =
double
---------------------------------------------------------
如果不想要元胞数组,可以加一句转化一下:
clear all;clc;
test = {'1','1','1','1','2','2','2','2','3','3','3','3','4','4','4','4'};
for n=1:length(test)
x{n}=str2num(test{n});
end
for m=1:length(x)
y(m)=x{m}(1)
end
y =
Columns 1 through 12
1 1 1 1 2 2 2 2 3 3 3 3
Columns 13 through 16
4 4 4 4
广告 您可能关注的内容 |