フィルターのクリア

getting rid of a loop

7 ビュー (過去 30 日間)
joseph Frank
joseph Frank 2012 年 7 月 25 日
Hi,
I have a cell array X which has around 1 million rows. each row has a 1x18 cell in it. I want to select columns 4,5,10,18 from each row. To do so I am running a loop v = regexp( X, ',', 'split'); ncol=[4 5 10 18];%numeric columns v2=nan(length(v),length(ncol));% numeric variables empty matrix
for j=1:length(v)
v0=[v{j,1}];
v2(j,1:length(ncol))=str2double(v0(1,ncol));
end
end
is it possible to avoid the loop and select columns 4,5,10,18 of each row of X?
  1 件のコメント
Image Analyst
Image Analyst 2012 年 7 月 26 日
Edit your question. Highlight the code part of the question. Click the "{} Code" box above to format it so that it looks like a regular program.

サインインしてコメントする。

回答 (2 件)

Nirmal
Nirmal 2012 年 7 月 25 日
編集済み: Nirmal 2012 年 7 月 25 日
b=[V(:,4) V(:,5) V(:,10) V(:,18)]
b will be what you want.
  2 件のコメント
joseph Frank
joseph Frank 2012 年 7 月 25 日
No,
It is giving an error that index exceeds Matrix dimenssions.
V has only one column and in each row of this column I have 1x18 cells
Nirmal
Nirmal 2012 年 7 月 25 日
change that V with X. I misread.

サインインしてコメントする。


joseph Frank
joseph Frank 2012 年 7 月 26 日
編集済み: joseph Frank 2012 年 7 月 26 日
Thanks Nirmal for your efforts but still it doesn't work. Just in case my question wasn't clear I will rephrase it here
X has the following format:is 00846UAB7,A.GB,A,07/01/2002,11:10:26,T,500000,101.84,2.21429,000,@,,,101.84,2.21429,101.84,2.21429,101.84 v = regexp( X, ',', 'split');
to obtain v=
<1x18 cell>
... for 1 million rows.
I want a matrix v2 that consists of columns 4 ,5,10 and 18 without running a loop/ I used in my initial codes v2=str2double(v0(1,ncol)); where v0 is a row obtained as :
for j=1:length(v)
v0=[v{j,1}];
v2(j,1:length(ncol))=str2double(v0(1,ncol));
end
end
from the loop descibed in the intial post;

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by