Sudden error "Conversion to double from struct is not possible"

6 ビュー (過去 30 日間)
David Slater
David Slater 2020 年 12 月 5 日
コメント済み: Walter Roberson 2020 年 12 月 6 日
The error message occurred suddenly after many successful runs of a script and without altering the line nor any near it. tried in command window and the result was the same. The line appears to be a precise replica of the example line in Matlab help.
>> set(gcf,'WindowState','maximized')
Error using set
Conversion to double from struct is not possible.
The Products box below will not allow me to enter MATLAB
The tags box below will not allow me to enter anything!

採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 5 日
You might have assigned a value to a variable named gcf
Or possibly you introduced a new function named gcf
which gcf
  10 件のコメント
David Slater
David Slater 2020 年 12 月 6 日
Thank you indeed, Walter. The problem is now solved. In my earlier efforts to add a title to a figure, I had changed
set(gcf,'WindowState','maximized')
to
gcf.WindowState='maximized';
and I had failed to realize that I hadn't changed it back. This had the effect of assigning a value to gcf each time a ran the script and turning it into a variable.This cancelled the result of
clear gcf
Changing the line in the script back to a set command has cured the problem. I will now gratefully accept your answer.
Thanks again.
David.
Walter Roberson
Walter Roberson 2020 年 12 月 6 日
Ah yes, that could do it.
Unfortunately gcf and gca are functions . Although with a relatively recent change to MATLAB it is possible to hack to be able to access properties of the object returned, you cannot assign to it:
>> struct('T', gcf).T.WindowState
ans =
'normal'
I do not recommend this hack.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by