Why am I getting "Index in position 2 exceeds array bounds. Index must not exceed 1"

3 visualizaciones (últimos 30 días)
This is my import function
When I load the music it says this. However, if i remove these the program works fine. But i need to extract both channels
rightChannel = y(:, 2);
this is supposed to extract the right channel, right? If so, then why am I getting
Index in position 2 exceeds array bounds. Index must not exceed 1.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 29 de Dic. de 2021
Editada: Cris LaPierre el 29 de Dic. de 2021
You haven't shared the complete error message, so I'm not sure what line is causing the error, but it is most likely this one:
app.y(:, 2)
The error itself is easy to explain. You are trying to index the second column of a variable that only has one column. Consider the following example.
A = rand(5,1)
A = 5×1
0.1658 0.1431 0.8805 0.6138 0.5775
% Works
A(2,1)
ans = 0.1431
% Doesn't work
A(1,2)
Index in position 2 exceeds array bounds. Index must not exceed 1.
  7 comentarios
Cris LaPierre
Cris LaPierre el 29 de Dic. de 2021
Editada: Cris LaPierre el 29 de Dic. de 2021
1. give it a different name
2. Generally in an app, it is preferable to not use 'input', as the whole idea behind an app is to have everything be contained there. Use an Edit Field component and query the value.
startpnt = app.StartEditField.Value
Generally speaking, once an answer has been accepted, it is best to ask a new question, especially if the new questions are unrelated to the original.
Cris LaPierre
Cris LaPierre el 29 de Dic. de 2021
Editada: Cris LaPierre el 31 de Dic. de 2021
That was made up example code. You have to use your actual variable and component names. Capitalization matters.
app.startpnt = app.STARTEditField.Value
EDIT: This thread may now seem confusing to follow. The OP has deleted several comments and reworded those that are still here, making it so the replies no longer appear to align with the questions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by