Error: Why does Matlab keep on saying this?
3 views (last 30 days)
Show older comments
As part of an exercise, I wrote the following code:
%define colors for each face
myred = [1, 0, 0];
mygreen = [0, 1, 0];
myblue = [0, 0, 1];
myyellow = [1, 1, 0];
mycyan = [0, 1, 1];
patchcolors = [...
myred;... %front
mygreen;... %back
myblue;... %right
myyellow;... %left
mycyan;... %top
mycyan;... %bottom
];
For the line starting with myred =...., the command window says:
" The expression to the left of the equals sign is not a valid target for an assignment."
The editor shows this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195299/image.png)
If I hover my cursor over the highlighted errors, this is what I get:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195300/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195302/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195303/image.png)
I don't see what is obviously wrong with the code. In fact, if I write the exact same line under that first line (myred=....), Matlab seems to find no error in it.
Advice? Suggestions?
3 Comments
Guillaume
on 6 Sep 2018
Most likely you're missing a closing ), } or ] on a line before the error. Post (or attach) your whole code.
Accepted Answer
YT
on 6 Sep 2018
The problem lies not with the code you provided, but with the code before that. I see that in your second screenshot, you ended your previous array with:
9,10,11,12,... %bottom
You just forget to add the bracket there
9,10,11,12,... %bottom
];
2 Comments
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!