0

I am having this problem that when I run the below written code in the main screen matlab does'nt give me a problem.

However if i write it in the editor then it complains that it is invalid syntax. Can you tell me what am i doing wrong or is it a bug?

Ques1 = { @(data) mean(data)  @(data) std(data) };
mean = Ques1 {1} (data(:,1)) # runs perfectly on the main compiler screen 

On my editor page the compilers complains on the = sign that a possible bracket is missing. However I do not understand why it works on the matlab line by line compiler !!

2
  • Does the editor give you a yellow or red alert on the line mean = Ques1 {1} (data(:,1))? Commented Feb 25, 2012 at 23:43
  • what is in your data variable for the second line? Commented Feb 27, 2012 at 15:07

3 Answers 3

3

Those two lines of code are absolutely correct. Somewhere in you code you have forgotten an open left bracket e.g. [ , { , (

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

1 Comment

+1 Try hitting Ctrl-A Ctrl-I in the editor to have it reindent based on syntax; this can help you spot mismatched brackets.
2

EDIT Now I understand what g24l was saying! Yes, that is likely the culprit of your problem.

Not sure what version of matlab you're using but when I run a very simple script:

data = kron(1:25,transpose(1:25)); % very simple 2D matrix of data;

Ques1 = { @(data) mean(data)  @(data) std(data) };
mean1 = Ques1 {1} (data(:,1)) % runs perfectly on the main compiler screen

It works perfectly on R2007B and R2009B, are you using an older or newer version? I suspect there is some other issue creeping up in your script. Also, as a matter of following Mathworks recommended programming procedures, I would encourage you not to name a variable or function the same name as another variable or function. In this instance I'm referring to mean = .... It's easy to get this stuff mixed up and then have nasty problems. If you need more help, please feel free to post more of your script. Hope this helps!

Comments

0

I don't have access to Matlab at the moment so I can't test this out, but your syntax doesn't look right to me. Try this:

Ques1 = {@(data)mean, @(data)std};
mean = Ques1{1}(data(:,1))

If you run it your way in your debugger, how many elements does it say are in your cell array?

Comments

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.