Replace values on a column filtering with a value

3 visualizaciones (últimos 30 días)
Alessandro Togni
Alessandro Togni el 27 de En. de 2021
Respondida: Daniel Catton el 27 de En. de 2021
Hi,
i have a matrix with 56 columns and want to replace with NaN values on a column N corresponding to positions on another column M containing values > of a threshold.
Let's say: if the i-th value of the column 56 is greater than threshold, replace the i-th value of the column N with NaN.
Logical indexing would be better.
Doing this i'm selecting the values greater than 8 on the columns, erasing the others.
R_mod=R(R(:, 56) > 8.0, :)
Thanks in advance,
Alessandro

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 27 de En. de 2021
hello
something like that :
%% some dummy data
A = (1:10);
In_Matrix =A'*A;
%% main code %%
Out_Matrix = In_Matrix;
threshold = 45;
col_index_to_test = 9; % column index where you do the test > threshold
col_index_to_replace = 8; % column indexwhere you want to replace values by NaN
ind = find(In_Matrix(:,col_index_to_test) > threshold);
Out_Matrix(ind,col_index_to_replace) = NaN;

Más respuestas (1)

Daniel Catton
Daniel Catton el 27 de En. de 2021
I think I understand what you mean, this works for my understanding of your problem but let me know if I have misunderstood. The user will input their values of 'YourMatrix', 'M' and 'N' and the script will output your 'NewMatrix'.
YourMatrix = ;
M = ;
N = ;
[x,y] = size(YourMatrix);
NewMatrix = YourMatrix;
for i = 1:x
j = YourMatrix(i,M);
if j <= 8
NewMatrix(i,N) = NaN;
end
end

Categorías

Más información sobre Linear Programming and Mixed-Integer Linear Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by