how to insert a calculated index to trim a data set?

조회 수: 2 (최근 30일)
flemingtb
flemingtb 2018년 11월 30일
답변: Mark Sherstan 2018년 11월 30일
I have a matrix KeyZ that needs to be custom trimmed based on user defined dimensions. The user inputs a 'width' value in mm and i'd like to use that to set the boundary of the data. For example.
KeyZ(:,[1:110,width:end])=[];
I'm getting the following error, which makes sense i just don't know how to do it correctly.
Index in position 2 is invalid. Array indices must be positive integers or logical values.
  댓글 수: 2
Georgios Pyrgiotakis
Georgios Pyrgiotakis 2018년 11월 30일
What's the format of the KeyZ matrix?
flemingtb
flemingtb 2018년 11월 30일
1800x800 double
I tried this, it still hung up.
Trim = KeyZ(:,[1:110,width:end]) %=[]; %Trim columns 1 - 255 and 652-end with []
Trim = KeyZ(1:100,:) %= []; %Trim rows 1-17 to []
[m,n] = size(Trim ); %Matrix Dim
[xg,yg]= meshgrid((0:n-1),(0:m-1));

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

답변 (2개)

Georgios Pyrgiotakis
Georgios Pyrgiotakis 2018년 11월 30일
I am assuming that you have a 1800 x 800 and what you are trying to do is to trim it to keep the rows
Trim = KeyZ(1:110,width:end)
Also the
Trim = KeyZ(1:100,:) %= []; %Trim rows 1-17 to []
will trim rows 101 to 1800 and keep all the columns

Mark Sherstan
Mark Sherstan 2018년 11월 30일
Use a diffferent variable name then width, it is a function used for tables and is used by MATLAB. You also need to ensure that your width (or now idx variable) is greater than 110 and less than 800. The following code should work for you:
idx = 500; % index location or width
KeyZ = rand(1800,800); % Some random 1800 x 800 matrix
KeyZ(:,[1:110,idx:end]) = [];

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by