Paji.R
Paji.R

Reputation: 155

Set text box as filename

I have audiowrite where I want the value of a text box to be the filename.

My current code does not work, an error says the value of filename is invalid. Anyone know how I fix this?

audiowrite(handles.edit4,'String',y,Fs);

Upvotes: 0

Views: 41

Answers (1)

Suever
Suever

Reputation: 65440

You need to retrieve the String property of the text box using either get(handles.edit4,'String') or if you have R2014b or newer you can use handles.edit4.String

filename = get(handles.edit4, 'String');

% In case "String" is a cell array
if iscell(filename)
    filename = filename{1};
end

audiowrite(filename, y, Fs)

Update

If you want to add an extension such as .mp3 you can simply use strcat to append the extension

audiowrite(strcat(filename, '.mp3'), y, Fs)

Upvotes: 2

Related Questions