Combine numeric and character array to display to operator
Show older comments
I have a script which uses a function to search a folder for files with that match inputs passed to the search function.
The output of the search function is a cell array which displays all of the potential matches. Ex:
searchres = filefinder(searchdirectory,'searchterm1','searchterm2')
The result of this function is the following:
searchres = 1×3 cell array
{'file1.xlsx'} {'file2.xlsx'} {'file3.xlsx'}
What I am attempting to do is to query the operator to select the single correct file to operate on via an input prompt.
prompt=input('Type the correct .xlsx file number (1,2,3...) to perform data reduction \n');
disp(searchres')
The user would type "1" to select the first file, "2" for the second, and so on until the list is complete. However, with more files present, I'd rather not have the user count 15-20 lines to figure out what number to type. I'd like for it to be displayed as follows:
1 'file1.xlsx'
2 'file2.xlsx'
3 'file3.xlsx'
...
n 'filen.xlsx'
I've tried using a loop to put the two together (column of numbers, column of text), but it doesn't work.
searchlen=length(searchres);
for i=1:searchlen
searchval=cell2mat(searchres(i))
searchselect(2,i)=searchres(i);
searchselect(1,i)=i;
end
But I get the error "Conversion to double from cell is not possible."
Am I going about this in the wrong way? I'm certian this is something that I can do.
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!