The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Need help: Filter values in a matrix
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

muguangde

7 Posts

Posted - 08/30/2012 :  2:57:57 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.5
Operating System: win7

Hi All,

I have a very simple question. I have a 200X200 matrix with element values ranged from 0 to 10, If I want to filter half of them and only get a new matrix with element values>5 and also output the column and row number of the element after filtering.

Is there a quick way to do it please?

Thanks in advance,
muguangde

Hideo Fujii

USA
1582 Posts

Posted - 08/30/2012 :  3:51:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi muguangde,

How about the following way?

1) Set the X/Y mapping to column/row index ("Matrix: Set Dimension/Labels" menu) such that the "From" and "To" values for X are 1 and the number of columns, and for Y are 1 and the number of rows. (If you have your own mapping, and don't want to change, you need to make a duplicate matrix.)
Note: You can do this also by the following command:
    mdim x1:=1 x2:=wks.ncols y1:=1 y2:=wks.nrows;
2) Convert the matrix to a worksheet ("Matrix: Convert to Worksheet" menu with "XYZ Columns" in Method option.

3) Using the Worksheet Query, extract the rows which match your condition (C>5).

Hope this works for you.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 08/30/2012 4:15:53 PM
Go to Top of Page

muguangde

7 Posts

Posted - 08/30/2012 :  4:51:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,Hideo,

Thank you very much for the reply. I followed your method and it is working quite well. Now I have my matrix converted into a worksheet, but I still have one more problem, my matrix is 200X200 in size and 40000 elements.

Is there any quick way filter them in the worksheet and output the column/row number(it must be a long list) please?

Thanks again,
muguangde
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 08/31/2012 :  10:40:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi muguangde,

Then, probably you need a LabTalk script, or an Origin C program to speed up.
Here is a sample script. Try to see if this runs enough fast, or not.

///////////////////////////////
threshold=5;
if(exist(%H)!=5) {type -b Activate a matrix; Return;};
%M=%H;
Window -t wks;
%W=%H;
Worksheet -a 1;
range r1=[%W]!1;
range r2=[%W]!2;
range r3=[%W]!3;
Window -a %M;
nc=wks.ncols; 
nr=wks.nrows;
kk=0;
break -b Scanning %M;
break -r 1 nc;
Loop(jj,1,nc) {
  break -p jj;
  Loop(ii,1,nr) {
    if(cell(ii,jj)>threshold) {kk++; r1[kk]=jj; r2[kk]=ii; r3[kk]=cell(ii,jj);}
  }
}
break -end;
Window -a %W;
///////////////////////////////
--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 08/31/2012 11:07:30 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000