uiputfile dont work anymore
3 views (last 30 days)
Show older comments
Hello Matlab Community I have following problem, I wrote a little app and now i want to save some .wav files and the user choose the directory. I choosed uiputfile for this problem, and it worked perfect the first 20 test runs. I have a bunch of audiofiles created by uiputfile, but now it doesent creates anything. The weird thing is, the backup cloud, does a backup, after saving, but there is no data.... please help, there is no error message, no problem, no bug.... I dont know what to do!
if true
%% Button pushed function: applyButton
function applyButtonPushed(app, event)
toggleValue = app.toggleSwitch.Value; %% gets toggle switch value %% part of the code
if ( strcmpi(toggleValue,'Fuzz') ) %%checks value, string comparing
if(app.valc==4)
app.in_fuzz=app.audio_norm_custom; %%get user normalized audio
app.audioout=fuzz(app,app.in_fuzz);
elseif (app.valc==3)
app.in_fuzz=app.audio_norm; %%get first input normalized audio
app.audioout=fuzz(app,app.in_fuzz); %%create fuzz sound
end
audiowrite((uiputfile('fuzz_out.wav')),app.audioout,app.Fs); %%create . wav audiofile and save it
[app.in_fuzz,app.fuzz_path]=uigetfile('.wav'); %%get audio back
app.UIFigure.Visible='off'; %%keep app displayed
app.UIFigure.Visible='on';
app.straudiopth=fullfile(app.fuzz_path,app.in_fuzz); %%create string
app.audioout2_fuzz=audioread(app.straudiopth); %%read audio
app.audioout3=audioplayer(app.audioout2_fuzz,app.Fs);
app.valc=1; %%control var for play/stop
app.audioin=audioplayer(app.audio_norm,app.Fs); %%load audio in player
app.dt_plot_out = 1/app.Fs; %%create plot values/datas
app.t_plot_out= 0:app.dt_plot_out:(length(app.audioout2_fuzz)*app.dt_plot_out)-app.dt_plot_out;
plot(app.plot_out,app.t_plot_out,app.audioout); %%plot audio
title(app.plot_out,'Fuzz')
elseif ( strcmpi(toggleValue,'Overdrive') ) %%same process for overdrive as described for fuzz
if(app.valc==4)
app.in_ovd=app.audio_norm_custom;
app.audioout_ovd=overdrive(app,app.in_ovd,app.Fs);
elseif(app.valc==3)
app.in_ovd=app.audio_norm;
app.audioout_ovd=overdrive(app,app.in_ovd,app.Fs);
end
audiowrite((uiputfile('o_out.wav')),app.audioout_ovd,app.Fs) ;
[app.in_ovd,app.ovd_path]=uigetfile('.wav');
app.UIFigure.Visible='off';
app.UIFigure.Visible='on';
app.straudiopth1=fullfile(app.ovd_path,app.in_ovd);
app.audioout2_ovd=audioread(app.straudiopth1);
app.audioout4=audioplayer(app.audioout2_ovd,app.Fs);
app.valc=2;
app.dt_plot_out = 1/app.Fs;
app.t_plot_out= 0:app.dt_plot_out:(length(app.audioout2_ovd)*app.dt_plot_out)-app.dt_plot_out;
plot(app.plot_out,app.t_plot_out,app.audioout_ovd);
title(app.plot_out,'Overdrive')
end
end
% code
end
1 Comment
Jan
on 5 May 2019
What exactly do you observe? "but now it doesent creates anything" is not clear enough. I do not understand thius also: "the backup cloud, does a backup, after saving, but there is no data".
Matlab's uiputfile fails, when the High Contrast mode of Windows is enabled. But this does not match your explanations.
Answers (2)
Darko Kulic
on 5 May 2019
3 Comments
Walter Roberson
on 6 May 2019
You are passing the result of uiputfile() directly to audiowrite() . That can only work if the user happened to select a file name in the current directory. uiputfile does not return complete file names: just like uigetfile, it returns the last part of the name in the first output, and the directory in the second output. You should be sending the output of uiputfile() into two variables and putting them together with fullfile()
Jan
on 6 May 2019
"it doesn't create anything" could mean, that you get an error message or that existing files are overwritten. Even if you repeat this and ask me to read it carefully again, you do not reveal what actually happens. You mention, that there are files copied to a backup. Does this mean that the files are created but empty?
As Walter has said already, uiputfile determines the file name and path only, so you cannot "create files" with it. I assume using the debugger will show you, what exactly happens. I guess, that your app.audioout_ovd is empty in the failing cases.
Your code contains:
if(app.valc==4)
app.in_ovd=app.audio_norm_custom;
app.audioout_ovd=overdrive(app,app.in_ovd,app.Fs);
elseif(app.valc==3)
app.in_ovd=app.audio_norm;
app.audioout_ovd=overdrive(app,app.in_ovd,app.Fs);
end
It is a safe programming style to define an else for all if's. What happens, if app.valc is neitehr 3 or 4?
By the way, what is the purpose of:
app.UIFigure.Visible='off'; %%keep app displayed
app.UIFigure.Visible='on';
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!