Hey all,
The basic start of my program i'm trying to write is to take user input of note values and create a wav file based upon these values but I'm having problems with parsing the user input and converting it to the particular frequency of that note..
Here is my code so far:
% SHOW INPUT DIALOG AND TAKE USER INPUT..
prompt={'1st Note','2nd Note','3rd Note','4th Note','5th Note','6th Note','7th Note'};name='Enter Note Values (C-B)..';num_lines=1;%list = {'B'};
%options.Interpreter = 'tex';
defaultans={'C','D','E','F','G','A','B'};answer=inputdlg(prompt,name,[1 50],defaultans);% TEST IF USER FORGETS AN INPUT..
for x = 1:length(answer)tf=isempty(answer);if tf==1 msgbox('You missed a note(s) out..','Error','error','modal');end% END IF..
end% END FOR..
% CONFIGURE INPUT TO VARIABLES..
Note1 = answer{1};Note2 = answer{2};Note3 = answer{3};Note4 = answer{4};Note5 = answer{5};Note6 = answer{6};Note7 = answer{7};% LOOP THROUGH ANSWERS AND ASSIGN FREQUENCY VALUES..
for x = 1:length(answer) if answer{x} == 'C' FreqX = num2str(261.626); elseif answer{x} == 'D' FreqX = num2str(293.665); elseif answer{x} == 'E' FreqX = num2str(329.628); elseif answer{x} == 'F' FreqX = num2str(349.228); elseif answer{x} == 'G' FreqX = num2str(391.995); elseif answer{x} == 'A' FreqX = num2str(440.000); elseif answer{x} == 'B' FreqX = num2str(493.883); end % END IF..end% END FOR..msgbox({'Freq1 is: ', FreqX, 'Hz' 'Note1 is: ', Note1});msgbox({'Freq2 is: ', FreqX, 'Hz' 'Note2 is: ', Note2});
Now although there are no errors, its working as intended. The msgboxes are simple to help me see the results as i build my program but the frequency it displays is always the final one in the if statement.
I could do if statements for EACH of the answer{} array but this would be a lot of code so what would be the best way to iterate through the answers and assign the correct frequency values..
I can't get my head around the best and easiest way..
Any ideas?
Thanks,
Paul
Best Answer