1

All i am trying to do is this:

    type = cell(size(A));
    ...
    i = find(A == 0);
    type{i} = 'pasok';

However it miserably fails is size(A) > 1 or if i is empty. Is there any workaround for this problem?

UPDATE -ERROR

type =

[]    []

ans =

 1     2

i =

 1     2

The right hand side of this assignment has too few values to satisfy the left hand side.

Error in ellipse (line 48) type{i} ='pasok';

7
  • 2
    'it miserably fails' doesn't really look like a Matlab error statement to me. If you tell us what the error message is we can provide better help. If you tell us what you are trying to do we can provide better help, right now I am wondering wha problem you are trying to workaround. I mean, you already know that the statement type{i} = 'pasok' fails when i is either empty or multi-valued, because you have read the error messages and the documentation. So what is the problem you are trying to solve ? Commented Jun 25, 2012 at 7:19
  • 1
    @HighPerformanceMark: "'it miserably fails' doesn't really look like a Matlab error statement to me." Every day you learn something new! (+1). Commented Jun 25, 2012 at 7:50
  • @Parhs So.... what exactly are you trying to accomplish? Commented Jun 25, 2012 at 7:58
  • @EitanT if you read it, it clearly shows that he is getting an error, and wants a workaround Commented Jun 25, 2012 at 8:01
  • @ahmet if you read my comment, it clearly shows that I'm not asking about the error, but rather about what he's trying to implement. Commented Jun 25, 2012 at 8:03

1 Answer 1

2

To assign one value to multiple cell-entries at once, you can use

[type{i}] = deal('pasok');

Note that type{i} has to be in square brackets.

Sign up to request clarification or add additional context in comments.

1 Comment

Good answer, I also would use logical indexing [type{A==0}]=deal('pasok'); as this is usually faster and in my opinion more intuitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.