matlab 'colorbar' error
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
  Brita Irving
 el 7 de Mayo de 2025
				
      Editada: Walter Roberson
      
      
 el 8 de Mayo de 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; 
^^^^^^^^^^^^^^^^^^^^^
  Walter Roberson
      
      
 el 8 de Mayo de 2025
				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'})) = [];
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




