obtain largest vector from n input files MATLAB
I'm developing a program that reads data from an excel file, it saves the data regarding to numbers in the variable num then it determines which vector from the data read is the largest one. I want to expand this code for n number of input files in an efficient way (not read and compare file by file). any recommendations on how to achieve this?
Suppose I want this code to work for file names finger1.xlsx to finger100.xlsx
filename='finger1.xlsx'; [num1,txt1] = xlsread(filename); filename='finger2.xlsx'; [num2,txt2] = xlsread(filename); filename='finger3.xlsx'; [num3,txt3] = xlsread(filename); filename='finger4.xlsx'; [num4,txt4] = xlsread(filename); filename='finger5.xlsx'; [num5,txt5] = xlsread(filename); if(length(num1)>length(num2)) parent=num1; rank=1; else parent=num2; rank=2; end if(length(num3)>length(parent)) parent=num3; rank=3; end if(length(num4)>length(parent)) parent=num4; rank=4; end if(length(num5)>length(parent)) parent=num5; end
You could write a loop and change the name of the file based on the loop variable i.
filename = sprintf('finger%d.xlsx', i);
If you do not want to compare file by file, you might store all the data from all the files and then use max to find the largest one.