将相同长度的内容存储到Matlab中的一个变量 [英] Store same length content to one variable in matlab
问题描述
我有一个包含一些行的文件,其内容如下:
I have a file with some rows with content as below :
1.000000 - 1.000200 0 -> 2 A-MPDU 1.000000 - 1.000100 SUCCESS 1.000100 - 1.000200 FAIL
1.000425 1 TIMEOUT
1.000150 - 1.000350 1 -> 3 A-MPDU 1.000150 - 1.000250 FAIL 1.000250 - 1.000350 FAIL
然后我想在拆分成不同的元素后将row1和row3合并到一个变量:
Then I want combine row1 and row3 to one variable after splitting to different element :
for z = 1:length(myTextArray)
temp = regexp(A{z,1}, ' ', 'split');
if cols == 15
C1 = temp;
end
end
但是C1仅存储最新的温度".如何使C1存储row1和row3的值(当然也存储在不同的行中)?
But C1 only stores the latest "temp". How to make C1 stores row1 and row3 value (of course in different row as well)?
推荐答案
使用以下代码:
ix = 0;
C1 = {};
for z = 1:length(myTextArray)
temp = regexp(A{z,1}, ' ', 'split');
if numel(temp) == 15
ix = ix + 1;
C1{ix} = temp;
end;
end;
基本上,您会在单元格数组C1
中创建一个新索引ix
.
Basically you create a new index ix
in the cell array C1
.
稍后编辑
这将创建2D单元阵列,而不是1D单元阵列的1D单元阵列:
This will create a 2D cell array rather than a 1D cell array of 1D cell arrays:
ix = 0;
C1 = cell(0,15);
for z = 1:length(myTextArray)
temp = regexp(A{z,1}, ' ', 'split');
if numel(temp) == 15
ix = ix + 1;
C1(ix, :) = temp;
end;
end;
基本上,这是EJG89先前给出的相同答案,不同之处在于它不会包含空单元格行.
which is, basically, the same answer EJG89 gave earlier, with the difference that it will not contain empty cell rows.
这篇关于将相同长度的内容存储到Matlab中的一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!