Replace values on a column filtering with a value

2 vues (au cours des 30 derniers jours)
Alessandro Togni
Alessandro Togni le 27 Jan 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

Réponse acceptée

Mathieu NOE
Mathieu NOE le 27 Jan 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;

Plus de réponses (1)

Daniel Catton
Daniel Catton le 27 Jan 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

Catégories

En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by