matlab 'colorbar' error

I am getting this error message thread when I try to add a colorbar to a figure, thanks for any help!:
>> colorbar
Check for incorrect argument data type or missing argument in call to function
'imag'.
Error in flipud (line 14)
x = flip(x,1);
Error in matlab.graphics.shape.internal.AxesLayoutManager/insertAboveAxes
Error in matlab.graphics.shape.internal.AxesLayoutManager.getManager
Error in legendcolorbarlayout (line 34)
hManager = matlab.graphics.shape.internal.AxesLayoutManager.getManager(hAx);
Error in matlab.graphics.illustration.ColorBar/setAxesImpl
Error in matlab.graphics.illustration.ColorBar/set.Axes_I
Error in matlab.graphics.illustration.ColorBar/set.Axes
Error in colorbar (line 238)
cbar.Axes = peeraxes;

12 Kommentare

Adam Danz
Adam Danz am 17 Jan. 2022
What does this return?
which colorbar -all
Better yet, what does this return:
which flip -all
Adam Danz
Adam Danz am 18 Jan. 2022
Walter Roberson's right - you're likely shadowing the flip function. I just created a flip.m and ran colorbar and it produced the same error.
Bill Johns
Bill Johns am 18 Jan. 2022
Bearbeitet: Adam Danz am 18 Jan. 2022
Thanks for the help.
I have no idea what it means but here's what that command returned after making the plot, which itself plotted fine:
>> figure
>> pcolor(sd,pbin,gvel_rel_bot)
>> axis('ij')
>> colorbar
Check for incorrect argument data type or missing argument in call to function
'imag'.
Error in flipud (line 14)
x = flip(x,1);
Error in matlab.graphics.shape.internal.AxesLayoutManager/insertAboveAxes
Error in matlab.graphics.shape.internal.AxesLayoutManager.getManager
Error in legendcolorbarlayout (line 34)
hManager = matlab.graphics.shape.internal.AxesLayoutManager.getManager(hAx);
Error in matlab.graphics.illustration.ColorBar/setAxesImpl
Error in matlab.graphics.illustration.ColorBar/set.Axes_I
Error in matlab.graphics.illustration.ColorBar/set.Axes
Error in colorbar (line 238)
cbar.Axes = peeraxes;
>> which flip -all
/Applications/MATLAB_R2021b.app/toolbox/matlab/elmat/flip.m
flip is a built-in method % connector.internal.LoggerLevel method
flip is a built-in method % matlab.internal.lang.capability.Capability method
flip is a built-in method % matlab.desktop.editor.RtcEditorState method
flip is a built-in method % mf.zero.meta.Language method
flip is a built-in method % slreq.datamodel.AttributeKindEnum method
flip is a built-in method % slreq.datamodel.AttributeRegType method
flip is a built-in method % slreq.datamodel.AttributeTypeEnum method
flip is a built-in method % slreq.datamodel.CustomIdNumbering method
flip is a built-in method % slreq.datamodel.MappingDirectionEnum method
flip is a built-in method % matlab.lang.OnOffSwitchState method
flip is a built-in method % matlab.internal.timer.CallBackTypeEnum method
flip is a built-in method % matlab.internal.timer.BusyModeEnum method
flip is a built-in method % matlab.internal.timer.ExecutionModeEnum method
flip is a built-in method % matlab.internal.reference.property.RefEntityType method
flip is a built-in method % matlab.internal.reference.api.EntityPrecision method
flip is a built-in method % matlab.internal.reference.property.DeprecationStatus method
flip is a built-in method % matlab.internal.reference.property.FunctionType method
flip is a built-in method % matlab.internal.reference.api.EntityCaseSensitivity method
/Applications/MATLAB_R2021b.app/toolbox/matlab/bigdata/@tall/flip.m % tall method
/Applications/MATLAB_R2021b.app/toolbox/parallel/gpu/@gpuArray/flip.m % gpuArray method
/Applications/MATLAB_R2021b.app/toolbox/parallel/parallel/@distributed/flip.m % distributed method
built-in % char method
built-in % double method
built-in % int16 method
built-in % int32 method
built-in % int64 method
built-in % int8 method
built-in % logical method
built-in % single method
built-in % uint16 method
built-in % uint32 method
built-in % uint64 method
built-in % uint8 method
>>
Steven Lord
Steven Lord am 18 Jan. 2022
Since the error message calls out the imag function let's check that it is not shadowed either.
which -all imag
Bill Johns
Bill Johns am 18 Jan. 2022
Bearbeitet: Adam Danz am 18 Jan. 2022
OK, here's what I get for 'imag':
>> which -all imag
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@char/imag) % char method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@double/imag) % double method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@int16/imag) % int16 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@int32/imag) % int32 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@int64/imag) % int64 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@int8/imag) % int8 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@logical/imag) % logical method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@single/imag) % single method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@uint16/imag) % uint16 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@uint32/imag) % uint32 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@uint64/imag) % uint64 method
built-in (/Applications/MATLAB_R2021b.app/toolbox/matlab/elfun/@uint8/imag) % uint8 method
imag is a built-in method % connector.internal.LoggerLevel method
imag is a built-in method % matlab.internal.lang.capability.Capability method
imag is a built-in method % matlab.desktop.editor.RtcEditorState method
imag is a built-in method % mf.zero.meta.Language method
imag is a built-in method % slreq.datamodel.AttributeKindEnum method
imag is a built-in method % slreq.datamodel.AttributeRegType method
imag is a built-in method % slreq.datamodel.AttributeTypeEnum method
imag is a built-in method % slreq.datamodel.CustomIdNumbering method
imag is a built-in method % slreq.datamodel.MappingDirectionEnum method
imag is a built-in method % matlab.lang.OnOffSwitchState method
imag is a built-in method % matlab.internal.timer.CallBackTypeEnum method
imag is a built-in method % matlab.internal.timer.BusyModeEnum method
imag is a built-in method % matlab.internal.timer.ExecutionModeEnum method
imag is a built-in method % matlab.internal.reference.property.RefEntityType method
imag is a built-in method % matlab.internal.reference.api.EntityPrecision method
imag is a built-in method % matlab.internal.reference.property.DeprecationStatus method
imag is a built-in method % matlab.internal.reference.property.FunctionType method
imag is a built-in method % matlab.internal.reference.api.EntityCaseSensitivity method
/Applications/MATLAB_R2021b.app/toolbox/ident/ident/@iddata/imag.m % iddata method
/Applications/MATLAB_R2021b.app/toolbox/nnet/deep/@dlarray/imag.m % dlarray method
/Applications/MATLAB_R2021b.app/toolbox/parallel/gpu/@gpuArray/imag.m % gpuArray method
/Applications/MATLAB_R2021b.app/toolbox/parallel/parallel/@codistributed/imag.m % codistributed method
/Applications/MATLAB_R2021b.app/toolbox/symbolic/symbolic/@sym/imag.m % sym method
>>
Bill Johns
Bill Johns am 18 Jan. 2022
I didn't install the Matlab Drive Connector, unless that somehow happened with the standard install dmg I downloaded.
BTW this was also happening to me with 2019b, before I upgraded to 2021b (and that was part of the reason I did).
Also I find that rebooting my mac seems to temporarily solve the problem (i.e., colorbar works without an error), but it always comes back. Very strange.
I wonder why your paths do not indicate "Shadowed" as shown below.
which flip -all
/MATLAB/toolbox/matlab/elmat/flip.m flip is a built-in method % Shadowed connector.internal.LoggerLevel method flip is a built-in method % Shadowed matlab.internal.lang.capability.Capability method flip is a built-in method % Shadowed matlab.lang.OnOffSwitchState method flip is a built-in method % Shadowed matlab.internal.reference.property.RefEntityType method flip is a built-in method % Shadowed matlab.internal.reference.api.EntityPrecision method flip is a built-in method % Shadowed matlab.internal.reference.property.DeprecationStatus method flip is a built-in method % Shadowed matlab.internal.reference.property.FunctionType method flip is a built-in method % Shadowed matlab.internal.reference.api.EntityCaseSensitivity method flip is a built-in method % Shadowed mf.zero.meta.Language method flip is a built-in method % Shadowed dig.config.CommandType method flip is a built-in method % Shadowed dig.config.HorizontalAlignment method flip is a built-in method % Shadowed dig.model.DisplayState method flip is a built-in method % Shadowed dig.model.EventDataType method flip is a built-in method % Shadowed dig.model.FunctionType method flip is a built-in method % Shadowed dig.model.ValidInBdType method flip is a built-in method % Shadowed dig.model.ViewMode method flip is a built-in method % Shadowed simulink.FindSystemTask.Status method flip is a built-in method % Shadowed sl.data.adapter.AdapterDiagnostic method flip is a built-in method % Shadowed sl.data.adapter.AdapterType method flip is a built-in method % Shadowed sl.data.adapter.ChangeType method flip is a built-in method % Shadowed slid.SourceIssue method flip is a built-in method % Shadowed slid.broker.SourceManagerSourceKind method flip is a built-in method % Shadowed targetframework.internal.repository.DataSource method flip is a built-in method % Shadowed coderdictionary.data.AccessFunctionSignaturesEnum method flip is a built-in method % Shadowed coderdictionary.data.AccessInterfaceEnum method flip is a built-in method % Shadowed coderdictionary.data.AccessModeEnum method flip is a built-in method % Shadowed coderdictionary.data.AllowedAccessEnum method flip is a built-in method % Shadowed coderdictionary.data.DataAccessEnum method flip is a built-in method % Shadowed coderdictionary.data.DataAccessTypeEnum method flip is a built-in method % Shadowed coderdictionary.data.DataInitEnum method flip is a built-in method % Shadowed coderdictionary.data.DataInstantiationEnum method flip is a built-in method % Shadowed coderdictionary.data.LatchingModeEnum method flip is a built-in method % Shadowed coderdictionary.data.PlacementEnum method flip is a built-in method % Shadowed coderdictionary.data.RTEWhenToCallRule method flip is a built-in method % Shadowed coderdictionary.data.ScopeEnum method flip is a built-in method % Shadowed coderdictionary.data.StatementsSurroundEnum method flip is a built-in method % Shadowed coderdictionary.data.StatusEnum method flip is a built-in method % Shadowed dastudio_util.cooperative.AsyncFunctionRepeaterTask.Status method flip is a built-in method % Shadowed matlab.unittest.Verbosity method flip is a built-in method % Shadowed matlab.unittest.internal.fixtures.FolderScope method flip is a built-in method % Shadowed matlab.internal.timer.CallBackTypeEnum method flip is a built-in method % Shadowed matlab.internal.timer.BusyModeEnum method flip is a built-in method % Shadowed matlab.internal.timer.ExecutionModeEnum method flip is a built-in method % Shadowed matlab.pyclient.Status method /MATLAB/toolbox/matlab/bigdata/@tall/flip.m % Shadowed tall method /MATLAB/toolbox/parallel/gpu/@gpuArray/flip.m % Shadowed gpuArray method /MATLAB/toolbox/parallel/parallel/@distributed/flip.m % Shadowed distributed method built-in % Shadowed char method built-in % Shadowed double method built-in % Shadowed int16 method built-in % Shadowed int32 method built-in % Shadowed int64 method built-in % Shadowed int8 method built-in % Shadowed logical method built-in % Shadowed single method built-in % Shadowed uint16 method built-in % Shadowed uint32 method built-in % Shadowed uint64 method built-in % Shadowed uint8 method
Brita Irving
Brita Irving am 7 Mai 2025
Verschoben: Walter Roberson am 7 Mai 2025
Was this ever resolved? I am having the same error, on windows and mac platforms. I just updated to R2024b from R2022b to resolve this but the error is still happening!
Generally speaking, these kinds of problems are most often due to having a third-party function with the same name as a Mathworks function.
To debug the problem, create a new directory and cd to the new directory. Then inside the new directory
restoredefaultpath; rehash toolboxcache
and try executing colorbar again from inside the new directory. If it works, then the problem was due to a third-party function with the same name as a mathworks function.
Brita Irving
Brita Irving am 7 Mai 2025
Bearbeitet: Walter Roberson am 8 Mai 2025
Thank you! I did that, and it indeed did work but when I tried which imag -all it still didn't show a third-party function with the same name, and there was no imag variable in my workspace.
In the end, I edited my startup.m, which contained a lot of addpath(genpath(...)) calls to different toolboxes installed over time. I tested which was causing the error, and removed it. Now the error is gone!
% TESTING ERROR
% okay, issue with some folder in matlab-utility because when commented out
% addpath(genpath('D:\MATLAB\matlab-utility')); in startup.m, the colorbar works fine.
% first, identify all folders in matlab-utility
d = dir('D:\MATLAB\matlab-utility');
d = d([d.isdir]);
d = d(4:end); % remove {'.'} {'..'} {'.git'}
% First, check that error does not happen
figure;
imagesc(peaks);
colorbar;
close
% Now loop through and add them one at a time and see if error comes up
for nfolder = 1:numel(d)
addpath(genpath(fullfile(d(nfolder).folder,d(nfolder).name)))
try
figure;
imagesc(peaks);
colorbar;
title(fullfile(d(nfolder).folder,d(nfolder).name))
catch
fprintf('error here: %s\n',fullfile(d(nfolder).folder,d(nfolder).name))
keyboard
end
pause(1)
close
end
% do a final check
addpath(genpath('D:\MATLAB\matlab-utility'));
figure;
imagesc(peaks);
colorbar;
title('D:\MATLAB\matlab-utility')
fprintf('function end\n')
This was the original error I was getting, that is now resolved.
Error in flip (line 33) throw(ME);
^^^^^^^^^^ Error in flipud (line 14) x = flip(x,1);
^^^^^^^^^^^^^^ Error in matlab.graphics.shape.internal.AxesLayoutManager/insertAboveAxes Error in matlab.graphics.shape.internal.AxesLayoutManager.getManager Error in legendcolorbarlayout (line 38) hManager = matlab.graphics.shape.internal.AxesLayoutManager.getManager(hAx);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in matlab.graphics.illustration.ColorBar/setAxesImpl Error in matlab.graphics.illustration.ColorBar/set.Axes_I Error in matlab.graphics.illustration.ColorBar/set.Axes Error in colorbar (line 241)
cbar.Axes = peeraxes;
^^^^^^^^^^^^^^^^^^^^^
d = dir('D:\MATLAB\matlab-utility');
d = d([d.isdir]);
d = d(4:end); % remove {'.'} {'..'} {'.git'}
That code assumes that . and .. and .git are the first three directories returned by dir(). That is a very common mistake. dir() returns files in the order reported by the operating system, rather than sorting files itself. The operating system in turn reports files in the order returned by the file system, rather than sorting files itself.
The order of files returned by NTFS is not documented. In practice it appears to be controlled by the NTFS file name encoding parameter. The NTFS file name encoding parameter of any given NTFS file system is in turn controlled by the languages settings of the person who created the NTFS file system (there is not explicit file name encoding command line setting when creating NTFS file systesm; it is whatever the user happened to be using.)
Given the usual file name encoding parameter... there are various file names that sort before '.' sorts.
What you should have instead of d = d(4:end) is a line such as
d(ismember({d.name}, {'.', '..', '.git'})) = [];

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 17 Jan. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by