Find and extract specific rows and column into new table

6 views (last 30 days)
This is what I have and it finds the correct rows but it is not creating a new table with the extracted values. It produces a 1x1 table. I am not sure what I am missing.
load Leaf1.txt;
% % Set data source
Wave = Leaf1(:,2);
Ref = Leaf1(:,3);
% % Locate data
R = find(Wave >= 625 & Wave <= 691)
NIR = find(Wave >= 829 & Wave <= 900);
% Create new matrix
New = Leaf1([276:342 2427:2493 4578:4644 6729:6795 8880:8946 11031:11097 13182:13248 15333:15399 17484:17550 19635:19701 480:551 2631:2702 4782:4853 6933:7004 9084:9155 11235:11306 13386:13457 15537:15608 17688:17759 19839:19910]);
% % Save new table
Ref_Leaf1=table(New);
writetable(Ref_Leaf1);

Accepted Answer

Walter Roberson
Walter Roberson on 17 Jun 2018
New = Leaf1([276:342 2427:2493 4578:4644 6729:6795 8880:8946 11031:11097 13182:13248 15333:15399 17484:17550 19635:19701 480:551 2631:2702 4782:4853 6933:7004 9084:9155 11235:11306 13386:13457 15537:15608 17688:17759 19839:19910], :);
Ref_Leaf1 = array2table(New, 'VariableNames', {'Wave', 'Ref'});
But I suspect you are more after
Leaf_R = array2table( Leaf1(R, :), 'VariableNames', {'Wave', 'Ref'});
Leaf_NIR = array2table( Leaf1(NIR, :), 'VariableNames', {'Wave', 'Ref'});
writetable(Leaf_R);
writetable(Leaf_NIR);

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!