フィルターのクリア

replace numbers in the matrix

4 ビュー (過去 30 日間)
EK
EK 2022 年 12 月 18 日
編集済み: Image Analyst 2022 年 12 月 19 日
Hello,
I have a matrix of 6 columns (an example attached here) that are: trials, stimulus IDs, Hit, Miss, CR, FA.
Hit, Miss, CR, FA columns are coded as a 0 and 1. Sometimes the correspondent rows in FA and CR column are coded with 1. I need to correct this and everywhere when FA row = 1 replace correspondent row im CR column with 0
Can anyone help with this?
  1 件のコメント
Torsten
Torsten 2022 年 12 月 18 日
Better you immediately give the matrix you expect as result in the above case to avoid unnecessary attempts.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2022 年 12 月 18 日
編集済み: Image Analyst 2022 年 12 月 18 日
Try this:
data = readmatrix('trial.log.xlsx');
% Colulmns are: trials, stimulus IDs, Hit, Miss, CR, FA.
% Find where last column, FA, is 1
rows1 = data(:, end) == 1;
% "replace correspondent row im CR column from with 0 "
% In English: "replace the element in the corresponding row in the CR column with 0"
data(rows1, 5) = 0
data = 19×6
1 4 0 0 1 0 2 3 1 0 0 0 3 3 1 0 0 0 4 4 0 0 1 0 5 3 0 1 0 0 6 4 0 0 0 1 7 3 0 1 0 0 8 4 0 0 1 0 9 4 0 0 1 0 10 3 0 1 0 0
  4 件のコメント
EK
EK 2022 年 12 月 18 日
yes it is only in case if both CR and FA are equal 1
Image Analyst
Image Analyst 2022 年 12 月 19 日
編集済み: Image Analyst 2022 年 12 月 19 日
Oh, I thought that "Sometimes the correspondent rows in FA and CR column are coded with 1" but that you only wanted to set CR to zero when "when FA row = 1". But if what you really meant was "when FA row = 1 AND when CR row = 1", then you can make the obvious change:
data = readmatrix('trial.log.xlsx');
% Colulmns are: trials, stimulus IDs, Hit, Miss, CR, FA.
% Find where 5th column is 1 and the last column, FA, is 1.
% That is, both 1 in the same row.
rows1 = (data(:, 5) == 1) & (data(:, end) == 1);
% "replace correspondent row im CR column from with 0 "
% In English: "replace the element in the corresponding row in the CR column with 0"
data(rows1, 5) = 0

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by