Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
flemingtb
flemingtb il 30 Nov 2018
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));

Accedi per commentare.

Risposte (2)

Georgios Pyrgiotakis
Georgios Pyrgiotakis il 30 Nov 2018
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 il 30 Nov 2018
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]) = [];

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by