I want to put the data from each function under the correct column with respect to the vector x. I've tried to transpose it but it still gives me the same answer in rows.
MATLAB: How to put data from a function into columns using frprintf
fprintf
Related Solutions
Nothing in the above code seems to point towards any error. You might have a variable called fprintf defined in your workspace, causing MATLAB to recognize fprintf to be a matrix you are trying to index into with your fprintf statement. Please check this and use a different variable name if you do have a variable called fprintf.
I still think repositioning the axis to make room for a marginal colorbar is the cleanest and most efficient approach (see the various position properties of axes).
However, here's how to add an axes under a cloned colorbar. The basic idea is to create a new axis on top of the existing colorbar, set the axis colormap properties to match the main axis, then add a new colorbar to the new axes. Then set the colorbar properties to match those of the initial colorbar. Toward the end of the code below, you can set the transparency level of the new axis. Note that the original colorbar is turned off but still exists. See inline comments for more detail.
% Open one of your figures
% Get fig, axes, and colorbar handles from current figure
% Assumes 1 axes and 1 colorbar per figure
fh = gcf(); axh = findall(fh, 'Type','Axes');cbh = findall(fh, 'Type','ColorBar');% Create an axis on top of the current colbar
ax2 = axes('position',cbh.Position,'XTick',[],'YTick',[],'Box','on'); % expand the size of the new axis
% The axis will be 4X wider and its height will be slight larger to make room for title
ax2.Position(1) = ax2.Position(1) - .01; ax2.Position(2) = ax2.Position(2) - .01; ax2.Position(3) = ax2.Position(3)*4; ax2.Position(4) = 1 - ax2.Position(2) - .01;% The new axis must match the color scale of the one we're imitating
ax2.Colormap = axh.Colormap; ax2.ColorScale = axh.ColorScale; % set colorbar in new axes (you can add other important properties as needed)
cb2 = colorbar(ax2); cb2.Position = cbh.Position; cb2.FontSize = cbh.FontSize; cb2.Limits = cbh.Limits; cb2.LimitsMode = cbh.LimitsMode; cb2.TickDirection = cbh.TickDirection; cb2.YAxisLocation = cbh.YAxisLocation; caxis(ax2,cbh.Limits)% Set title of colorbar
th = title(cb2,cbh.Title.String,'Units','Normalize');th.Position(1) = th.Position(1) - min(0,th.Extent(1)-.00); %Move title to fit on axes
% set transparency of new axes (undocumented)
% v---transparency (0:1)
ax2.Color = [1 1 1 .6];% Turn off old colorbar (keep it around in case you need to reference it later)
cbh.Visible = 'off';
Best Answer