Insert variable name into string
32 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joseph
am 12 Nov. 2014
Beantwortet: Guillaume
am 13 Nov. 2014
I'm writing a function that allows users to input a filename to load that file. I'm going to use this function multiple times in GUI checkboxes so that a user can choose which files they want to pull up. The problem is, I can't figure out how to tell users what variable they should be entering. This is what I have so far (only the first few lines).
function [ output_args ] = loadExcel( Name )
inputdlg('Please enter the name for the' Name 'xls file: ','Excel Name');
Is there a way for me to plug in the variable for "Name" into my inputdlg string?
0 Kommentare
Akzeptierte Antwort
pietro
am 13 Nov. 2014
Try this:
inputdlg(['Please enter the name for the' Name 'xls file: '],'Excel Name');
0 Kommentare
Weitere Antworten (1)
Guillaume
am 13 Nov. 2014
Yo can use pietro's answer or strcat but I find sprintf to be a lot more readable for this. It's also a lot more flexible as you can have strings, characters, numbers, currencies, etc. inserted in your string in a well defined way:
inputdlg(sprintf('Please enter the name for the %s xls file: ', Name), 'Excel Name');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!