Scatter plot error "Vectors must be the same length" only when running the function, not in the command line

1 view (last 30 days)
Hi yall,
I'm trying to produce a scatter plot of two 1x4 vectors and when I run the scatter plot in the command line it works, but when I use the function I wrote I get the error message "Vectors must be the same length". It worked before with other vectors, so the code itself should work, which leaves me out of ideas about what could be the problem.
The vectors are Mtau=[0.897720769,0.990296539,0.537536690,0.005224619]; and Mwasht=[0.897720769 0.988775858 0.381407954 0.008648834];
The error should be somewhere around the two scatter plots (line29)
My code for the function is the following:
function combinedscatter(M1,M2,err1,err2,sigpos,siglevel)
% M=padcat(all data of one lysate e.g. concentrations)
% M1&M2 = Medians of data to be plotted
% err1&err2 = STDs corresponding to plotted data
% sigpos = {[x1(n),x1(n)],[x2(n),x2(n)]}; -> positions of dots sign. different, index positions
% in x1&x2
% siglevel = []; vector of p values
if nargin<=10
GroupedData={M1 M2};
Concentrations={'0' '5' '50' '500'};
PlotColors={'c' 'm'};
N = numel(GroupedData);
delta = linspace(-.3,.3,N); %// define offsets to distinguish plots
width = .2; %// small width to avoid overlap
cmap = hsv(N); %// colormap
legWidth = 1.8; %// make room for legend
labels = Concentrations; %// center plot: use real labels
sz=35;
fig1=figure;
hold on
%for n=0:0.1:1.5
% l=line([0 180], [n n],'Color',[0.9 0.9 0.9],'LineWidth',0.2,'LineStyle','--');
%end
x1=[2 5 50 500];
x2=[3 6 51 501];
s1=scatter(x1,M1,sz,'b','filled');
s2=scatter(x2,M2,sz,'r','filled');
xticks([0 1 10 100]);
xticklabels(Concentrations)
xlim([0 600]);
xlabel('Tau Protein Concentration (nM)');
ylim([0 1.5]);
yticks(0:0.1:1.5);
ylabel('Relative speed reduction after protein addition');
errorbar(x1, M1, err1, '.b');
errorbar(x2, M2, err2, '.r');
liney=[0:0.1:1.5];
hx1=sigstar(sigpos,siglevel);
%Y=get(hx1(1,1),'YData'); Y(4)=1.24; set(hx1(1,1),'YData',Y);
%line([56 146],[Y(4) Y(4)],'Color','k','LineWidth',1.0)
legend([s1 s2],{'Tau-GFP' 'Washout'},'Location','northeastoutside')
%title('Speed Reduction Cell Lysates');
end
  1 Comment
dpb
dpb on 25 Jun 2019
We can't run the function w/o the rest of the data inputs...and creating them locally won't prove anything about what you did...
Also, when posting an error, it is important to post the EXACT error message as it shows up on the screen in context with the command line that produced it -- otherwise we have no context nor the call stack output, etc., etc., ...
Set a breakpoint in the function and step through with the debugger with the same line and data you used before to find your error -- either one of logic in the function or data size mistake.
BTW, the function is very "brittle" in the sense it will be easily broken with such errors as this when you're passing one array (Y) to plot, against a fixed (X) vector that isn't necessarily congruent. Even if you only use the function right now for four points, it's usefulness is markedly constrained if something changes the slightest in your data in that instead of being general it is necessary to actually edit the function itself...and once done for that new case, the old cases no longer work with the same function. Makes for a lot more work and errors like you're having...

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!