Replace values on a column filtering with a value

4 ビュー (過去 30 日間)
Alessandro Togni
Alessandro Togni 2021 年 1 月 27 日
回答済み: Daniel Catton 2021 年 1 月 27 日
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

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 1 月 27 日
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;

その他の回答 (1 件)

Daniel Catton
Daniel Catton 2021 年 1 月 27 日
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

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by