Prev: Cell mode turned on, but code folding isn't working
Next: MWMCR instance could not be initialized
From: db on 12 May 2010 13:14 Hi, I am pretty new to matlab. I am trying to create a new column variable "newcl", but I don't get newcl variable in the workspace. could anyone help me ? Thanks ! a = [1,1,2,3,5,10,20,13,2,8,12,2,4,5,9,4,10]' b = [1,2,3,4,5,6,7,8,9,10,11,6,4,5,20,3,4]' if (a > b) newcl = -1; end
From: Steven Lord on 12 May 2010 13:20 "db" <daronnebonneau(a)gmail.com> wrote in message news:586df769-beb0-4b84-9012-0947acde6a21(a)l31g2000yqm.googlegroups.com... > Hi, I am pretty new to matlab. I am trying to create a new column > variable "newcl", but I don't get newcl variable in the workspace. > could anyone help me ? Thanks ! > > a = [1,1,2,3,5,10,20,13,2,8,12,2,4,5,9,4,10]' > b = [1,2,3,4,5,6,7,8,9,10,11,6,4,5,20,3,4]' > > if (a > b) Type the following command and look at the Remark labeled something like "Nonscalar conditions" in the document that appears for an explanation why the body of your IF statement is not being executed: doc if Do you want a vector of zeros and -1's the same length as a (and b, since it's the same length) where newcl(k) is -1 if a(k) > b(k) and newcl(k) is 0 otherwise? If so, you can use logical indexing. newcl = zeros(size(a)); % Preallocate newcl to be the correct size newcl(a > b) = -1; Alternately, the SIGN function might be of use to you. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: us on 12 May 2010 13:43 db <daronnebonneau(a)gmail.com> wrote in message <586df769-beb0-4b84-9012-0947acde6a21(a)l31g2000yqm.googlegroups.com>... > Hi, I am pretty new to matlab. I am trying to create a new column > variable "newcl", but I don't get newcl variable in the workspace. > could anyone help me ? Thanks ! > > a = [1,1,2,3,5,10,20,13,2,8,12,2,4,5,9,4,10]' > b = [1,2,3,4,5,6,7,8,9,10,11,6,4,5,20,3,4]' > > if (a > b) > newcl = -1; > end one of the many solutions r=-1*(a>b); us
|
Pages: 1 Prev: Cell mode turned on, but code folding isn't working Next: MWMCR instance could not be initialized |