Compare value in one column and replace string in another column

조회 수: 1 (최근 30일)
Ubu
Ubu 2012년 6월 4일
Dear all,
I imported a very long logfile with textscan using the %s (string) for all columns, given that I have both strings and numbers within column:
M =
{20132x1 cell} {20132x1 cell} {20132x1 cell} {20132x1 cell} {20132x1 cell}
In column 5 I have reaction time data. I column 3 I have "hit", "miss" or "correct" labels. I would like to clean my data, so that whenever column 5 has a value below 2000 ms or above 40000 ms the correspondent column 3 would be replaced with 'miss'.
I introduced a loop alpha declaring the size of M (I need this loop for additional operations), and between this loop I would like to clean the data:
for alpha = 1:size(M{1},1)
%idea which doesn't work
if str2num(M{5}{Z2}) <= 2000; change to 'miss' in M{3}}{Z2}
if str2num(M{5}{Z2}) >= 20000; change to 'miss' in M{3}}{Z2}
end
Any suggestion would be highly appreciated.
Sincerely,
Udiubu

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 6월 4일
x = cellfun(@str2num,M{5});
M{3}(x <= 2000 | x >= 40000) = {'miss'};
  댓글 수: 2
Ubu
Ubu 2012년 6월 5일
Hi Andrei,
Thanks for your answer.
Unfortunately, I'm getting the following error message:
??? Error using ==> cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Do you know why?
An alternative solution might be to work the other way round:
If M{3} has "hit" && {5} has a value less than 2000 or higher than 40000, change M{3} to "miss".
Thanks again!
Udiubu
Andrei Bobrov
Andrei Bobrov 2012년 6월 5일
What contains M {5}?,
in my case:
for example:
M{5} = {'200';10000';'50000'}

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


Ubu
Ubu 2012년 6월 5일
I now set up UnformOutput to false:
x = cellfun(@str2num,M{5},'UniformOutput', false);
but a new error appears regarding the following line:
M{3}(x <= 2000 || x >= 40000) = {'miss'};
??? Undefined function or method 'le' for input arguments of type 'cell'.
Sorry to bother, I really need this precious help.
Sincerely,
Udiubu

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by