Why am I getting "Index in position 2 exceeds array bounds. Index must not exceed 1"
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Cris LaPierre
on 29 Dec 2021
Edited: Cris LaPierre
on 29 Dec 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)
% Works
A(2,1)
% Doesn't work
A(1,2)
7 Comments
Cris LaPierre
on 29 Dec 2021
Edited: Cris LaPierre
on 29 Dec 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
on 29 Dec 2021
Edited: Cris LaPierre
on 31 Dec 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.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!