How to index a column of data
Show older comments
The problem asks for us to find the lowest salary for each worker and the find the column number associated with the lowest salary. A cell array called match_book has been created where the first element is the names, the second element is the IDs, and the third element is salary. The data table for salary is given below where rows correspond with each worker while the column designates a year. Using the min function and the match_book variable, generate a vector with the lowest salary and another vector with the corresponding column number (1 through 7). The code for finding lowest salary is below. Cannot find the corresponding column number.
78 88 56 67 85 96 63
45 98 42 79 55 61 74
56 80 45 83 70 51 44
73 42 90 86 82 55 43
98 91 82 56 94 77 72
98 96 59 81 98 68 87
49 81 97 79 73 61 96
99 86 42 49 48 90 47
98 85 66 47 49 75 74
69 63 63 70 55 73 68
88 79 86 98 91 95 40
48 50 88 60 55 57 60
65 83 51 75 89 86 49
95 41 69 53 54 85 88
for j=1:14
lowSal(j)=min(match_book{3}(j,:)); %outputs lowest salary
end
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!