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

1 次查看(过去 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 个评论
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
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 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by