Replacing specific rows in a matrix.

조회 수: 1 (최근 30일)
Elaheh
Elaheh 2018년 5월 10일
댓글: sloppydisk 2018년 5월 10일
I would like to replace the cells with the following features (those whose types are 9 or 12 and their ID is one of these numbers, 2,11,12). Then I want to replace them with NaN. However, indexB is a vector of 0 s only.
indexB = ( (Type == 9|Type ==12) & (IDscript ==2|IDscript==11|IDscript==12) );
RT(indexB)=NaN;
  댓글 수: 2
James Tursa
James Tursa 2018년 5월 10일
Have you looked at your data to make sure you have any spots that match all of the criteria?
Elaheh
Elaheh 2018년 5월 10일
Yes. It does. Here is my data attached. I had to change xlsx to xls to be able to attach the file.

댓글을 달려면 로그인하십시오.

채택된 답변

sloppydisk
sloppydisk 2018년 5월 10일
a = xlsread('Book2.xls');
indexB = (a(:, 2) == 9|a(:, 2) ==12) & (a(:, 6) ==2|a(:, 6)==11|a(:, 6)==12);
find(indexB)
This gives me 6 indices: 29, 30, 363, 364, 573 and 574.
  댓글 수: 2
Elaheh
Elaheh 2018년 5월 10일
Thank you. Is this different from your code? indexB = (mergedData(Type) == 9|mergedData(Type) ==12) & (mergedData(IDscript) ==2|mergedData(IDscript)==11|mergedData(IDscript)==12 ); where a is a matrix (mergedData) and (:,2) is Type? Mine does not work.
sloppydisk
sloppydisk 2018년 5월 10일
The idea is the same but is mergedData just a 748x6 double? What is the data type of "Type" and "IDscript"?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Elaheh
Elaheh 2018년 5월 10일
merged file (748*6) is the content of the excel file I sent you. Ive just started using MATLAB. Type= mergedData(:,2); accuracy= mergedData(:,3); RT= mergedData(:,4); TypeScript=mergedData(:,5); IDscript= mergedData(:,6);
  댓글 수: 1
sloppydisk
sloppydisk 2018년 5월 10일
Yeah that should work. You can attach the script if it's still not working for you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by