How to select the specific rows that I want in matrix using for loop?
1 view (last 30 days)
Show older comments
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
Answers (2)
Walter Roberson
on 8 May 2017
A = CombineFeatureAll(1:50,1:344);
c2 = [ones(25,1); -ones(25,1)];
t = [c2, A];
dlmwrite('testing.te', A, 'precision', 6);
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!