How to create a programme that will increase its increment of the size of array with a push button ? Using GUIDE
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x = (1:1);
a = get(handles.listbox1,'Value');
x(end+1)= a;
set(handles.text3,'String',num2str(a));
disp(x);
Basically, I want to create an array of variables with different values each and play them with function 'sound'. The array of variables are selected by user using variables from listbox and are added into array using 'add pushbutton'. For example I have a listbox of 'A' 'B' 'C', and when the user chose the order 'C' 'A' 'A' 'B' 'B' to be sounded. How do I create that code to put in what user selected from listbox and put them into array accordingly?
2 commentaires
Réponse acceptée
Jan
le 3 Mai 2021
With some guessing:
function pushbutton1_Callback(hObject, eventdata, handles)
Value = get(handles.listbox1, 'Value');
Data = get(handles.listbox1, 'String');
Selected = Data{Value};
% Append selection from list box to text field:
old = get(handles.text3, 'String');
set(handles.text3, 'String', [old, Selected]);
end
8 commentaires
Jan
le 7 Mai 2021
Modifié(e) : Jan
le 7 Mai 2021
"connect strings and variables which both have the same name" - this is far too complicated. Use the contents of the string to decide, which sound to play:
Str = '';
% Now append the notes in the callbacks - here emulated by code:
Str = [Str, 'C3 '];
Str = [Str, 'D3 '];
Str = [Str, 'C4 '];
... etc.
Finally you can "play" the notes:
Notes = strsplit(Str, ' '); % ==> {'C3', 'D3', 'C4', ...}
for k = 1:numel(Notes)
switch Notes{k}
case 'C3'
freq = 130.81;
...
end
sound(sin(freq * 2 * pi * (0:1/8192:.4)));
end
% See: https://pages.mtu.edu/~suits/notefreqs.html
See also:
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!