Plotting cell arrays, arbitrary size
4 views (last 30 days)
Show older comments
I'm trying to plot an arbitrary number of curves contained in a 2xN cell array. Row 1 is the XData, Row 2 contains the YData. I have verified all vectors (of doubles) are the same length.
The code:
[C{1,k},C{2,k}]=MyFun(...);
plot(C{:})
returns the error "Too many input arguments." I have tested with the size of C as 2x1 and 2x2.
I ensure that the output vectors generated in MyFun are row vectors with (though I think this is unnecessary):
z=reshape(z,[1 numel(z)]);
Oddly enough, I have taken this idea (plot(C{:})) from other code that works perfectly.
Any thoughts as to what is causing the error and how to fix?
0 Comments
Answers (2)
Jan
on 26 Feb 2012
Please post the type and size of the two outputs of your MyFun function and explain, what "k" is. If "plot(C{:})" works depends on the contents of the cell C.
Perhaps this works - but this is pure guessing:
plot(C{:, k})
I have no idea, what z is and why you have to reshape it.
4 Comments
Jan
on 27 Feb 2012
Do the vecors in C all have the same length? If so, you can create a matrix instead:
for k = length(c):-1:1 % Backwards for pre-allocation
[C1(k, :), C2(k, :)] =MyFun(a(k), b(k));
end
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!