An easy way to input song chords into a structure of MATLAB
Show older comments
Hello. I'd like to know the way to enter the name of the song chords into the structure of MATLAB easily.
I do research about the related between chords and a piece of music, and I analyze the chords progression in MATLAB. Howerver, it takes too many time to enter the name of chords by hands like this;
chords = struct( ...
'name', {}, ... % name of chords(ex: 'Cmaj7')
'start_sec', {}, ... % start time[s]
'end_sec', {} ... % end time[s]
);
N=input('the number of chords: ');
BPM=input('BPM: ');
chords(1).start_sec=0;
for i=1:N
fprintf('\n===== Chord %d =====\n', i);
chords(i).name=input('Name: '); %''
Start=input('Start beat: ');
chords(i).start_sec=(60/BPM)*4*(Start-1);
if i >= 2
chords(i-1).end_sec=(60/BPM)*4*(Start-1);
end
end
ends=input('End beat: ');
chords(N).end_sec=(60/BPM)*4*ends;
save("chords_yoruni.mat","chords");
I am a beginner when it comes to programming, so I don't have any idea. I would like you to tell me even small things.
Thank you for your help
2 Comments
INPUT() is a rather tedious and unreliable way to enter data. A much better approach is to import the data from a file, webpage, or something like that. Do you have a well-formatted source for these data?
Chino
on 14 Jan 2026
Accepted Answer
More Answers (0)
Categories
Find more on Direction of Arrival Estimation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!