| Thread Closed |
MATLAB Array Operations |
Share Thread | Thread Tools |
| Jul7-08, 12:57 PM | #1 |
|
|
MATLAB Array Operations
Hi,
How can I find the following from an array with entries of 0, 1, and >1: Find the sum of all the entries in the matrix that are not equal to 0. Find the sum of all the entries in the matrix. Find the sum of all the zero and 1 entries in the matrix. How to remove the entries in the matrix that are not equal to 0, one by one. Thanks! |
| Jul7-08, 01:04 PM | #2 |
|
|
I guess I can simplify my question:
I have a matrix A that contains values of 0, 1, and values that are greater than one. I need to remove the entries in the matrix that are greater than 1 until the number of values that are 0 and 1 outnumber the number of values that are greater than 1. Then I need to display the new matrix B that contains the result of the aforementioned operation. Hope that helps and thanks in advance! |
| Jul7-08, 02:23 PM | #3 |
|
|
Alright, so I have this so far:
function[newInteractions]=prune(interactions) while( sum(interactions(interactions~=0)) > sum(interactions(interactions<=1)) ) i=max(interactions); interactions(i)=[]; end newInteractions=interactions; I have a feeling that this can be improved in terms of speed -- the max function seems to be very slow. Can this be improved? |
| Apr27-09, 10:39 AM | #4 |
|
|
MATLAB Array Operations
Hi
If you array is something like: A=[1 0 0 0 1 0 1 0 25 5 8 69 0 0 1 0 1 0 1 1 1 1 0 4 7 0 1] A quick way to remove all the bumf greater than 1 in your array is: A(A>1)=[]; ______ For your summing problems try: x=find(A>1) %This will return all the points greater than 1 in your data. y=length(x) %This will give you a number corresponding to the number of successful finds. |
| Thread Closed |
| Thread Tools | |
Similar Threads for: MATLAB Array Operations
|
||||
| Thread | Forum | Replies | ||
| Matlab: How to apply filters to and ECG signal using matlab? | Math & Science Software | 2 | ||
| MATLAB Array Pre-allocation help! | Math & Science Software | 4 | ||
| converting from an array of function values to coordinate array of different length | Programming & Comp Sci | 3 | ||
| Array operations in Matlab????? | Math & Science Software | 6 | ||
| Matlab char array help please? | Math & Science Software | 2 | ||