필터 지우기
필터 지우기

Double to cell conversion.

조회 수: 4 (최근 30일)
Dwight
Dwight 2012년 9월 4일
I'm trying to store a string of characters in my [data_accuracy] variable (instead of storing for example 0 or 1) based on a conditional if statement. cellstr and num2str or { } based approaches have not worked and continue to give me the error: Conversion to cell from double not possible. Any suggestions? Thanks!
Example:
if data(i,1) == 1;
data_accuracy(i,1) = 'hit';
elseif data(i,1) == 2;
data_accuracy(i,1) = 'miss';
end
  댓글 수: 1
Rick Rosson
Rick Rosson 2012년 9월 4일
This approach is not a very efficient way to code an algorithm. Why do you want to have strings instead of numbers?

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

답변 (4개)

Jan
Jan 2012년 9월 4일
pool = {'hit', 'miss'};
data_accuracy = pool(data(:,1));

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 4일
편집: Azzi Abdelmalek 2012년 9월 4일
%use {} instead ()
data=randi(3,10,1) %example
for k=1:size(data,1)
if data(k,1)==1
data_accuracy{k,1} = 'hit';
elseif data(k,1) == 2;
data_accuracy{k,1} = 'miss';
end
end

Sean de Wolski
Sean de Wolski 2012년 9월 4일
편집: Sean de Wolski 2012년 9월 4일
data = (rand(10,1)>0.5)+1
c = cellstr(repmat('hit',size(data)))
c(data==2) = {'miss'}

Rick Rosson
Rick Rosson 2012년 9월 4일
Please try the following instead:
isAccurate = ( data(:,1) == 1 );
HTH.
Rick

카테고리

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