Is there another way to write test{1,1:10}=' ' ?

1 vue (au cours des 30 derniers jours)
Megna Hari
Megna Hari le 19 Août 2014
Réponse apportée : Jan le 20 Août 2014
Because obviously test{1,1:10}=' ' doesn't work:
"The right hand side of this assignment has too few values to satisfy the left hand side."
I had previously done test=cell(1,10) but ideally I want some sort of blank value in there that's not [] so when I later do a char() on each entry in the cell it won't complain that it can't do it.
  1 commentaire
Megna Hari
Megna Hari le 19 Août 2014
Also, I dont want a for loop like this:
for i=1:10
test{1,i}='';
end
because it takes too long and this is going to be in a function that gets called approximately 1,870,000 times using cellfun.

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 19 Août 2014
test(1,1:10) = {' '}
  1 commentaire
Megna Hari
Megna Hari le 19 Août 2014
Thank you! That's exactly what I want :)

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 20 Août 2014
Or shorter, if all elements are wanted:
test = cell(1,10);
test(:) = {' '};
Or:
test = repmat({' '}, 1, 10);

Catégories

En savoir plus sur Resizing and Reshaping Matrices 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!

Translated by