MATLAB Answers

0

Old Matlab script not running on newer version

Asked by Roberto Filippi on 4 Oct 2019
Latest activity Commented on by Roberto Filippi on 4 Oct 2019
Hi,
I wonder if somebody could help.
I have a simple MATLAB 2007b script that I'd like to use with a newer version (I use 2016b now).
I did some changes myself, but I am not a programmer and the script does not work.
The messages I get are:
-------
1)
WARNING: This session of your experiment was run by you with the setting Screen('Preference', 'SkipSyncTests', 1).
WARNING: This means that some internal self-tests and calibrations were skipped. Your stimulus presentation timing
WARNING: may have been wrong. This is fine for development and debugging of your experiment, but for running the real
WARNING: study, please make sure to set Screen('Preference', 'SkipSyncTests', 0) for maximum accuracy and reliability.
ans =
Error using Screen
See error message printed above.
2)
Error using audiowrite
The value of 'filename' is invalid. Expected input to be one of these types:
char
Instead its type was double.
EDIT: long script text removed and uploaded as a file.

  4 Comments

Show 1 older comment
Thank you Stephen,
I am using the latest psychotoolbox.
I got around the screen issue, but I am still stuck with the audiowrite.
I think the problem is that I replaced the old command wavwrite with audiowrite, but the line is the same:
wavwrite(transpose(recordedaudio), 8000, 16, strcat(subj_name,'/',num2str(block_num),'.wav'));
What the procedure should do, is to create a wav file everytime my participants in the experiment read a word aloud. Wav files should be progressively and automatically numbered in the "data" folder.
Do you have any idea how to resolve this problem?
Thanks!
R
I don't know what the parameters were for wavwrite, but
doc audiowrite
gives you the valid signatures for audiowrite.
The filename is the first argument, whereas in wavwrite it appears to have come at the end (this is why you get that particular error message - you are giving it y when it expects the filename). I assume the 'y' argument is your recordedaudio and the 8000 is Fs (sample frequency)? I don't know what the 16 represents though. There are a bunch of Name, Value pairs supported so if you know what the 16 is supposed to represent you may find it in those.
The 16 is the 'BitsPerSample' of audiowrite.

Sign in to comment.

1 Answer

Answer by Guillaume
on 4 Oct 2019
 Accepted Answer

The equivalent of your wavwrite using audiowrite is:
audiowrite(fullfile(subj_name, sprintf('%d.wav', block_num)), recordedaudio.', 8000, 'BitsPerSample', 16);
Notes:
  • I've replaced the strcat by fullfile. fullfile is a better way of building paths.
  • I've replaced the num2str + string concatenation, by sprintf. It's a better way of constructing strings in my opinion.
  • I've replaced the transpose by its much shorter form: .'

  1 Comment

Fantastic! Thanks!
It works perfectly now.
Thanks all of you for your help!
Rob

Sign in to comment.