From: Zukri on 11 Jul 2010 20:37 Hi. I have a matrix U = (8, 10, 12 , 14) I would like to shown them in a graph as a legend by using the Matrix 'U' i.e. (8 is for the first line, 10 is the second line and so on). As oppose to simply typing --> legend('8','10','12','14'). This is because Matrix 'U' is input by the user and changes the legend. How do I do this?
From: Walter Roberson on 11 Jul 2010 21:28 Zukri wrote: > I have a matrix U = (8, 10, 12 , 14) > I would like to shown them in a graph as a legend by using the Matrix > 'U' i.e. (8 is for the first line, 10 is the second line and so on). As > oppose to simply typing --> legend('8','10','12','14'). > This is because Matrix 'U' is input by the user and changes the legend. > > How do I do this? tUs = str2num(U.'); legend(tUs{:});
From: Zukri on 12 Jul 2010 06:56 Thanks a lot, Walter. :) However, I've still got a problem. Here's what I've got from MatLab: U = 10 12 14 16 Name Size Bytes Class Attributes U 1x4 32 double So I've applied as mentioned; > tUs = str2num(U.'); > legend(tUs{:}); and the error - Requires string or character array input. So im guessing that my U is already in string characters since I did put 'str2num' earlier. So i went straight to > legend(U{:}); and the error - ??? Cell contents reference from a non-cell array object. I dont understand what the error means. Also, what does U{:} mean? Thanks alot!
From: Paul on 12 Jul 2010 07:40 "Zukri " <buster_2020(a)hotmail.com> wrote in message <i1esc8$a7q$1(a)fred.mathworks.com>... > Thanks a lot, Walter. :) However, I've still got a problem. Here's what I've got from MatLab: > > U = > 10 12 14 16 > > Name Size Bytes Class Attributes > U 1x4 32 double > > So I've applied as mentioned; > > tUs = str2num(U.'); > > legend(tUs{:}); > and the error - Requires string or character array input. > > > So im guessing that my U is already in string characters since I did put 'str2num' earlier. So i went straight to > > legend(U{:}); > and the error - ??? Cell contents reference from a non-cell array object. > > I dont understand what the error means. Also, what does U{:} mean? Thanks alot! I think he ment: tUs = num2cell(U.'); and not: tUs = str2num(U.'); It's just a guess. Try it this way.
From: Walter Roberson on 12 Jul 2010 11:09
Zukri wrote: > Thanks a lot, Walter. :) However, I've still got a problem. Here's what > I've got from MatLab: > > U = > 10 12 14 16 > > Name Size Bytes Class Attributes > U 1x4 32 double > So I've applied as mentioned; >> tUs = str2num(U.'); >> legend(tUs{:}); > and the error - Requires string or character array input. tUs = cellstr(str2num(U.')); legend(tUs{:}); should do it. > Also, what does U{:} mean? F(V{:}) is the same as if you had written F(V{1}, V{2}, V{3}, ... V{end}) provided that V is a cell array. See the Getting Started section of the documentation for more information about cell arrays. |