Figure set color error

Hi,
I get this very annoying error which just blocks me :
figure; set(gcf,'color','w'); ??? Index exceeds matrix dimensions.
wtf ?! Setting color works when I start Matlab. Then, when I try doing it in a script. I get this error. And this error then just happens all the time even if I just type the above in the command window with a new figure.
I am running Matlab 2011a on MacOSX 10.7.3. Please help, it is urgent. I need my data to be plotted properly for an upcoming conference and this stupid error just blocks my whole progress.
Thanks a lot for any help.

 Risposta accettata

Andreas Goser
Andreas Goser il 21 Mag 2012

0 voti

When it is urgent - call Technical Support and don't rely on the community ;-)
But my guess is that you use variable or function that conflicts with your code line. Imagine what happens if gcf is a 1x2 variable.

Più risposte (3)

Jan
Jan il 21 Mag 2012
I think it is the scalar variable called "set", which stops your program from working correctly. See:
which set -all
It is recommended not to shadow built-in function by variables to avoid such unexpected problems. But such problems appear frequently in this forum, such that accidental shadowing cannot be called "unexpected" actually. Therefore I'd even dare to claim, that the forum is powerful enough to fix this problem.
Another idea is the standard procedure:
dbstop if error
Then Matlab stops when the error occurs. Then "whos" reveal the current variables and splitting the command into parts and run them in the command line reveals the underlying problem soon.
Yves
Yves il 21 Mag 2012

0 voti

Hi Andreas, Thanks for this super quick reply. I have checked for this by just typing gcf between the 2 above commands to see what it looks like, the error even happens if gcf = 2. I think it is somehow memory related. In a smaller Workspace it does not happen using the exact same script. The error message is just completely misleading. I will check with my larger dataset again later. Thanks!

1 Commento

Andreas Goser
Andreas Goser il 21 Mag 2012
GCF overlay was just an example. This also can be FIGURE, SET and sometimes even stuff that is used in called functiions.

Accedi per commentare.

Yves
Yves il 21 Mag 2012

0 voti

Thanks to both of you. Sorry, Andreas I did not get your point when I first read your post. But yes, very stupid error of mine, there is a variable named "set", because I sorted my data in sets of images....
And of course both of you are right, one should not give function names to variables. In the rush, I did not pay attention and because of the large Workspace I did not see the lower end of variables. Beginners mistake.
Thanks again.
PS : Sorry, Jan I could only accept one answer. Andreas was first ;)

1 Commento

Jan
Jan il 21 Mag 2012
I'm happy if your problem is solved. And I think, this experience will help you to avoid this mistake multiple times in the future.
If you like to, you can vote for an answer also.

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by