How to select the specific rows that I want in matrix using for loop?

7 ビュー (過去 30 日間)
ai ping Ng
ai ping Ng 2017 年 5 月 6 日
回答済み: Walter Roberson 2017 年 5 月 8 日
I have 150 X 344 matrix, 150 is the file numbers that I need to examine and 344 is my total number of features ('CombineFeatureAll'). I want to undergo 1-50 rows for testing and another 51-150 rows for training. Inside the 1-50 rows, the number smaller than 25 will be 1 else -1. I know by coding like this size(CombineFeatureAll,1) will get all the rows, but how can I limit it to only 50 rows? Below is my coding for testing part.
%start
for c2 = 1:size(CombineFeatureAll,1)
%for label
if c2<=25
str1=['1' ' '];
else
str1=['-1' ' '];
end
for c1 = 1:size(CombineFeatureAll,2)
str1 =[str1 ['',num2str(c1),':' num2str(CombineFeatureAll(c2,c1)) ' '] ];%feature set
end
dlmwrite('testing.te', str1, 'delimiter', '', 'precision', 6,'-append');
end
  1 件のコメント
Adam
Adam 2017 年 5 月 8 日
What do you actually want the output to be?

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

回答 (2 件)

ai ping Ng
ai ping Ng 2017 年 5 月 8 日
編集済み: Walter Roberson 2017 年 5 月 8 日
A = CombineFeatureAll(1:50,1:344);
for c2 = 1:size(A,1)
%for label
if c2<=25
str1=['1' ' '];
else
str1=['-1' ' '];
end
for c1 = 1:size(A,2)
str1 =[str1 ['',num2str(c1),':' num2str(A(c2,c1)) ' '] ];%feature set
end
dlmwrite('testing.te', str1, 'delimiter', '', 'precision', 6,'-append');
end
It can be run this way but this maybe not a good method?

Walter Roberson
Walter Roberson 2017 年 5 月 8 日
A = CombineFeatureAll(1:50,1:344);
c2 = [ones(25,1); -ones(25,1)];
t = [c2, A];
dlmwrite('testing.te', A, 'precision', 6);

カテゴリ

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