LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2006, 11:38 PM   #1
hedpe
Member
 
Registered: Jan 2005
Location: Boston, MA
Distribution: Debian
Posts: 380

Rep: Reputation: 30
matlab, comparing matrixs?


Hey everyone,

I have two files which contain numbers such as:
Code:
gnychis@monster ~/school/thesis/host_analysis/detection $ cat test1
1
2
3
4
gnychis@monster ~/school/thesis/host_analysis/detection $ cat test2
2
3
Here is the current status of my script, i read in both files to matrixes:
Code:
function [] = correlations ( filename1, filename2);  % read in params
warning off

[set1] = textread(filename1, '%d');
[set2] = textread(filename2, '%d');

set1
set2
So if I run it with "sets_test test1 test2" i see:
Code:
set11 =

     1
     2
     3
     4


set2 =

     2
     3
Now what I want to do is be able to say something like "2 out of 2 values from set2 exist in set1" and "2 out of 4 values from set1 exist in set2"

So I am looking for some way to compare the two matrix and how many elements from one belong in the other. I'd greatly appreciate any help!

Thanks!
George
 
Old 10-28-2006, 01:17 PM   #2
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
Below I assume the values are all distinct, as in your example. Matlab uses matrices to represent everything, but the above look like plain lists. So I'm not using matlab but plain old Unix tools (after all it's Linuxquestions.org):
Code:
wc -l test{1,2}
tells you the "of 4 in test1" and "of 2 in test2" part. (You can ignore the "total 6" line at the end.)
Code:
sort test{1,2} | uniq -d | wc -l
tells you there are 2 lines (matrix element values) in common.

If that doesn't solve your problem, please tell us, and maybe post a more realistic example.

Last edited by Quigi; 10-28-2006 at 01:58 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing directories ursusman Linux - Newbie 5 07-04-2006 06:56 AM
comparing drives warinthepocket Linux - General 7 09-23-2005 05:56 PM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 06:49 AM
Comparing distros dpeirce Linux - General 17 01-26-2005 11:08 PM
Comparing filesystems for changes Astryk Linux - Software 1 04-12-2004 10:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration