Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Deleting value in a matrix based on the row in another matrix Date: Mon, 10 May 2010 08:36:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 49 Message-ID: <hs8ghl$22b$1@fred.mathworks.com> References: <hs7fag$90p$1@fred.mathworks.com> <hs8283$936$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1273480565 2123 172.30.248.35 (10 May 2010 08:36:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 10 May 2010 08:36:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2346709 Xref: news.mathworks.com comp.soft-sys.matlab:634153 "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hs8283$936$1@fred.mathworks.com>... > "CNN " <cnln2000@yahoo.co.uk> wrote in message <hs7fag$90p$1@fred.mathworks.com>... > > Good day, > > I wrote the code below to open a series of files, find the standard deviation of each column in the file (3) and and add each standard deviation to a new matrix. It's not perfect, I know. The problem is that some files in the series do not exist or have different names. These do not matter as I am allowed to safely skip some files. But I need to delete those values form the matrix [t] based on the matrix [point] as [point] will have all zeros rows for the missing files. > > > > I'm just starting out in matlab and I wrote this code based on ideas from this forum. I know the problem is with this line of code > > t(:,point == 0,2) = []; > > as the other work fine when I delete it. Any suggestions on the correct code will be appreciated. > > Thanks > > P.S I know what the code "point(all(point==0,2),:) = [];" does but what does "point==0,2" do? > > > > point = zeros(1000,3); > > t = 41000:1000:379500; > > n = length(t); > > for i = 1:n; > > x = ['trail',num2str(t(i),'%08.0f'),'.dat']; > > g = dir (x); > > if ~isempty(g) > > M = dlmread(x,'',1,0); > > s = std (M,1); > > point(i,:) = s; > > end > > end > > t(:,point == 0,2) = []; > > point(all(point==0,2),:) = []; > - - - - - - - - - > I don't know what t(:,point == 0,2) = []; does either. It would seem to imply that 't' is three-dimensional. It ought to be the same as for the next line, namely > > t(:,all(point == 0,2)) = []; > > Actually since t is a vector, there is no need for the first colon. It can be simply > > t(all(point == 0,2)) = []; > > The same is not true for 'point' since it is truly two-dimensional. > > Roger Stafford Hi, I tried your suggestion and received the error message "Index of element to remove exceeds matrix dimensions. Error in ==> disper36500_500 at 15 t(all(point==0,2)) = [];" so I added the line "point(n+1:end,:) = [];" before your code and it worked. Thank you so very much. I still want to know want the code "point==0,2" does. I've read up on the "all" function but I still don't get that bit. Thanks once again.