An easy way to input song chords into a structure of MATLAB

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 comentarios

Stephen23
Stephen23 el 14 de En. de 2026
Editada: Stephen23 el 14 de En. de 2026
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?

Thank you for your reply.

I used a webpage to get information. It's a website for just singing and playing guitar, so it's not compiled in a table format for easy processing.

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 14 de En. de 2026
AVOID the function input. It only hurts your code, preventing you from growing. Learn to use other solutions for data input. One simple approach is to use a spreadsheet. Just put all of your data into a spreadsheet. Then you read it in with one line of code. Of course, you can also use a text file, then read it into MATLAB using a tool like readtable, textread, csvread, etc.
I looked at a few websites with guitar chords. Admittedly, the websites I looked at do not seem to be written so as to be easily scraped programmatically. And that means someone would need to do the work.
One idea might be to use one of the many AI chatbots around to do some of the work for you. Of course, since asking the right question is always the hard thing about using an AI tool well, that is a problem for me since I am pretty clueless about music in any form. However, I tried the MATLAB AI chat playground, using this query:
"D-chord major fingering"
You might be able to use what it returns, to then get something reasonable.

1 comentario

Thank you for your abvice.
I will try using an AI chat and other tool harder.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Etiquetas

Preguntada:

el 14 de En. de 2026

Comentada:

el 21 de En. de 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by