필터 지우기
필터 지우기

How to create a submatrix from a matrix, keeping all columns and a certain number of rows?

조회 수: 4 (최근 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

채택된 답변

Guillaume
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?
Note that you can use the debugger to help you find out what is going wrong. If you issue
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
Matias
Matias 2016년 11월 19일
Thank you very much. Clearly it was the value of b that was equal to zero. Very simple error that I wasn't able to see.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
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,:) ;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by