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

1 vue (au cours des 30 derniers jours)
ai ping Ng
ai ping Ng le 6 Mai 2017
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

Réponses (2)

ai ping Ng
ai ping Ng le 8 Mai 2017
Modifié(e) : Walter Roberson le 8 Mai 2017
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 le 8 Mai 2017
A = CombineFeatureAll(1:50,1:344);
c2 = [ones(25,1); -ones(25,1)];
t = [c2, A];
dlmwrite('testing.te', A, 'precision', 6);

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by