I have a variable with a string that I would like to use as a filename, how do I input that string into a function rather than the variable name?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
AThomas
am 21 Jun. 2020
Kommentiert: AThomas
am 22 Jun. 2020
As below, I have a dialog box asking me for a filename.
It will then add the file extension onto the end.
answer = inputdlg(fileName,dlgtitle,dims,definput);
fileName1 = strcat(answer,'.dxf');
FID = dxf_open(fileName1);
I've tried numerous different ways, and they all end up with errors.
The code works normally if I hardcode the file name into the dxf_open function. e.g. 'Export.dxf'
0 Kommentare
Akzeptierte Antwort
the cyclist
am 22 Jun. 2020
Bearbeitet: the cyclist
am 22 Jun. 2020
I think I see the problem. Did you notice that the output of the inputdlg command is a cell array? You need the contents of that cell array, which is the character array you want. So you need something like this:
fileName1 = strcat(answer{:},'.dxf');
Note the {:} after answer, to get at the contents of the cell array.
Weitere Antworten (1)
the cyclist
am 21 Jun. 2020
I don't have dxf_open, but the following -- which is effectively the same as what you posted -- works for me:
answer = 'test';
fileName1 = strcat(answer,'.dxf');
fid = fopen(fileName1,'w');
fprintf(fid,'test_write')
fclose(fid)
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!