Double to cell conversion.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Rick Rosson
le 4 Sep 2012
This approach is not a very efficient way to code an algorithm. Why do you want to have strings instead of numbers?
Réponses (4)
Azzi Abdelmalek
le 4 Sep 2012
Modifié(e) : Azzi Abdelmalek
le 4 Sep 2012
%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
0 commentaires
Sean de Wolski
le 4 Sep 2012
Modifié(e) : Sean de Wolski
le 4 Sep 2012
data = (rand(10,1)>0.5)+1
c = cellstr(repmat('hit',size(data)))
c(data==2) = {'miss'}
0 commentaires
Rick Rosson
le 4 Sep 2012
Please try the following instead:
isAccurate = ( data(:,1) == 1 );
HTH.
Rick
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!