load specific file - make name

2 views (last 30 days)
N
N on 14 Jun 2014
Answered: Image Analyst on 14 Jun 2014
I would like to choose specific files to open, without having to type the filename or select it. Specifically I have files with number 1 through 10. I would like to first use input to let me choose a number. And then I would like to load that specific file. However that doesn't work for me. Can anybody help? The filesnames are for example: 'filtered_emg_1.mat'
k = input('Please give number filtered emg file : ');
emgdata = load('filtered_emg_' k '.mat');

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 14 Jun 2014
Edited: Azzi Abdelmalek on 14 Jun 2014
k = input('Please give number filtered emg file : ');
emgdata = load(['filtered_emg_' num2str(k) '.mat']);
%or
emgdata = load(sprintf('filtered_emg_%d.mat',k))
  1 Comment
N
N on 14 Jun 2014
Thank you ! This was exactly what I needed !

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Jun 2014
Seems not very user friendly to me. Why use such a primitive method? At the very least, use inputdlg() instead of input(). But better, why don't you have a listbox with all the files listed where the user can simply click on the filename? That would be so much nicer for your user and you can make sure that only files exiting are listed - the user won't have to worry about typing in a "missing" number. See MAGIC_GUI or Tutorial for GUIDE

Categories

Find more on Startup and Shutdown 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!