Replace values on a column filtering with a value
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alessandro Togni
am 27 Jan. 2021
Beantwortet: Daniel Catton
am 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
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 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;
0 Kommentare
Weitere Antworten (1)
Daniel Catton
am 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!