How to create a submatrix from a matrix, keeping all columns and a certain number of rows?
26 次查看(过去 30 天)
显示 更早的评论
Hello. I have a big matrix, called "A", of which I want to extract a submatrix "B" consisting off all the columns but only a certain number of consecutive rows, let's say from row "b" to row "c" ("b" and "c" are obtained from an if statement). What I've tried is:
B = A([b:c],:);
But I get the message
"Subscript indices must either be real positive integers or logicals."
How should I do it? Thanks a lot
0 个评论
采纳的回答
Guillaume
2016-11-18
编辑:Guillaume
2016-11-18
The error message clearly tells you what the problem is, the b:c vector contains values that are either non-integer or smaller than 1. Clearly, your if statement that calculates these values does not do what you want.
What are the actual values of b and c and what is the code used to generate them?
dbstop if error
before running your code, then it will pause at the line causing the error and you can look at the values of b and c.
更多回答(1 个)
KSSV
2016-11-18
A = rand(100) ; % create a random matrix
iwant1 = A(5:10,:) ; % picking columns 5 to 10
idx = [3 4 7 9 20] ; % pick these columns
iwant2 = A(idx,:) ;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time-Frequency Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!