COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### collecting data in loops

• Email
• Follow

```How do I store results generated in a loop when they are of different lengths?

for i=1:390
find(mat(:,4)==i);
end;

I'm searching a matrix for values in the 4th column.
Because of the data therein, find will return a different number of indices for each value of i
(find i==1 returns 100 indicies, i == 2 returns 75, etc)

I need to store those results as they are collected, and refer back to them by the value of i as an index.

I'm a newbie and would appreciate your help. Thanks.
```
 0
Reply lcaruso (10) 5/2/2010 9:02:10 PM

See related articles to this posting

```radar wrote:
> How do I store results generated in a loop when they are of different lengths?
>
> for i=1:390
>     find(mat(:,4)==i);
> end;

Use cell arrays.

foundindices{i} = find(mat(:,4)) == i;

Noitice the {} instead of () .
```
 0

```On May 3, 1:02=A0pm, radar <lcar...@tds.net> wrote:
> How do I store results generated in a loop when they are of different len=
gths?
>
> for i=3D1:390
> =A0 =A0 find(mat(:,4)=3D=3Di);
> end;
>
> I'm searching a matrix for values in the 4th column.
> Because of the data therein, find will return a different number of indic=
es for each value of i
> (find i=3D=3D1 returns 100 indicies, i =3D=3D 2 returns 75, etc)
>
> I need to store those results as they are collected, and refer back to th=
em by the value of i as an index.
>
> I'm a newbie and would appreciate your help. Thanks.

You need to use a cell array:
c{i}=3Dfind(mat(:,4)=3D=3Di);
Note the curly brackets.

Don't use i or j as indices.
By default, Matlab treats them as sqrt(-1).
Use symbols like k, m, n, ia, etc.
```
 0

2 Replies
439 Views

Similar Articles

12/7/2013 8:27:57 AM
page loaded in 26568 ms. (0)

Similar Artilces:

Data Structures...
VB6 doesn't provide many commonly used data structures such as Hashtables, so I was wondering are there any implementations\libraries out there that provide some extra data structures above Collection? Any help greatly appreciated.. Noel On 3 Jun 2005 00:45:54 -0700, "Noel" <vbgooglegroups@yahoo.com> wrote: >VB6 doesn't provide many commonly used data structures such as >Hashtables, so I was wondering are there any implementations\libraries >out there that provide some extra data structures above Collection? > >Any help greatly appreciated.. I don't think we're officially "supposed" to care about the implementation of the collection. :-) Seriously, there are many sites that have data structures. "Slice and Dice" from William M. Rawls has some data structures, but no hash implementation, that I know of. The hash implementation I have uses arrays - I got it from a copyrighted book so I don't think I should post it. James Vincent Carnicelli has some thoughts on ad-hoc data structures without the need for classes. VBDox, by Mihayl Stamenov has some data structures, particularly a dictionary - but it uses

Virtual Data?
Why doesn't c++ support virtual data? It supports class data of type pointer to function (that's what virtual functions really are). In terms of implementation, why can't I have other types of data in my vtable? RTTI could be implemented this way instead of as a special case for the compiler. It would also be useful for class specific memory management implementations. -- Daniel A. Graifer "Daniel Graifer" <graifer@earthlink.net> wrote in message news:9IuOc.20376\$iK.11537@newsread2.news.atl.earthlink.net... > Why doesn't c++ support virtual data? It supports class data of type > pointer to function (that's what virtual functions really are). In > terms of implementation, why can't I have other types of data in my vtable? > > RTTI could be implemented this way instead of as a special case for the > compiler. It would also be useful for class specific memory management > implementations. > > -- > Daniel A. Graifer > "Why" something is done (in the standard) probably isn't best discussed here. But, here goes anyway... I can't imagine where I would need to use "virtual

Selecting Data in Scatter Plot
Hello all, I have a 2D scatter plot of 500-2000 points. I have clustered the data based on their location and nearness to other points in the plot. What I would like to be able to do is to select several clusters on the plot and combine them into a single cluster. My main issue has been finding a way to select a number of clusters from the graph. The brush tool seemed like the first obvious approach. However, I did not know how to get the brush tool to automatically return which clusters had been highlighted so I could combine them. I tried to open the brush tool and rewrite some... further analysis much easier. This example doesn't use brushing, however, I'd argue that the command line implementation is at least as easy... % Generate some fake clusters using mvrnd MU1 = [1 2]; SIGMA1 = [2 0; 0 .5]; cluster1 = mvnrnd(MU1,SIGMA1,100); MU2 = [-3 -5]; SIGMA2 = [1 0; 0 1]; cluster2 = mvnrnd(MU2,SIGMA2,100); MU3 = [4 -5]; SIGMA3 = [.5 0; 0 1.5]; cluster3 = mvnrnd(MU3,SIGMA3,100); MU4 = [-2 -9]; SIGMA4 = [.1 0; 0 .3]; cluster4 = mvnrnd(MU4,SIGMA4,100); data = vertcat(cluster1, cluster2, cluster3, cluster4); X

I've recently discovered some bad blocks on a Fujistu SCSI (MAM3367MP), diagnosed using the disk utilities that came with my Adaptec 29160N. Does anyone know what happens to the data that are written to bad blocks? I'm tempted to just let the verify utility remap the blocks. Problem is, this drive is my boot drive, and I'm not sure whether by doing so I'll end up with an unbootable. "Lynd Bacon" <ldb@lba.com> wrote in message news:eMqdnQZxId1qhQTcRVn-uA@comcast.com > I've recently discovered some bad blocks on a Fujistu SCSI (MAM3367MP), > diagnosed using the disk utilities that came with my Adaptec 29160N. > Does anyone know what happens to the data that are written to bad blocks? It's gone. That's why it is a bad block: the data can't be read (reliably). > I'm tempted to just let the verify utility remap the blocks. Problem is, this > drive is my boot drive, and I'm not sure whether by doing so I'll end up > with an unbootable. If it isn't already it won't be after remapping (reassign). Btw, it is better to rewrite the bad blocks than reassigning them permanently

Microfocus & Oracle data types
Greetings, I'm having trouble with ESQL: Scenario: Oracle 9i running on my PC (seemed a good idea) Microfocus Cobol 3.014 ditto I'm not using a pre-compiler. When using a cursor to fetch an Oracle-defined Decimal(7,3), no data-type I've tried as the receiving variable seems to work. I've tried: MF's ESQL tool-generated s9(4)v9(3) Comp-3 and my own interventions with plain Comp & then plain Display. My 'evidence' is from inspecting via the Animator. Also, moving the variable to another, 9(4)v999 display & inspecting that. Any hints would be welcome. .... (no such apparent trouble using Sybase <sigh>) Regards Michael Hi Michael. What SQLCODE/SQLSTATE/SQLERRMC are you getting returned on the FETCH statement? Could you also tell me which ODBC driver (and version) you're using please, and also whether you're running the latest set of fixpacks for NX 3.0 (which is quite an old product now)? Finally, if you use the OpenESQL Assistant to generate the copybook -- which using my copy of NX 4.0, generates the hvar as PIC S9(04)V9(03) COMP-3 -- and also an app to fetch the data from your table, does that run through cleanly

compiled exe missing data, no ctf file
;\$(PROJECTDIR)/matlab/cameratidget.matlab/cors_data/UpdateEphemeris.m</file> </category> <category name="Other files"><!--Do not modify the value of the name attribute, unless it is a class name.--> <file>\$(PROJECTDIR)/externals/Oracle_10_1_0_5/ojdbc14.jar</file> </category> <category name="C/C++ files"><!--Do not modify the value of the name attribute, unless it is a class name.--></category> </file_info> <packaging> <name>Untitled2_pkg</name>

A Fast sorting algorithm for almost sorted data
I am currently trying my hand at a compressor for the hutter prize. So far my compressor has potential but is nowhere near ready. It does however make heavy use of sorting. So spent some time trying to find a specialise sorting algorithm which would sort this type of data very quickly. There is plenty of information on the usual general sorting algorithms on the net however I did not have much luck finding one which would be very efficient on almost sorted data. I would like to ask whether any one has knowledge of such a sorting algorithm? In my desperation i have made a potentially new sorting algorithm which I am currently calling Run sort. It seems to be on average twice as fast as java's standard java.util.Arrays.sort(). According to Java's API... "The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance. " I also compared it to GNU complier's implementation

returning structure of data from a callback funtion
Hello everyone, how can I return my structure of data once is updating from a callback function to the main program? %This s my structure of data called st: st: hfigure: {[1] [] [3] [] []} hz: [0.1000 0.1000 0.1000 0.1000 0.1000] deltaz: [1 1 1 1 1] icxx: [0 0 0 0 0] isxxy: [0 0 0 0 0] %This is the callback function "stoprecording" to update my structure of data st: hseek=uicontrol('parent',st.hfigure{e},'String', 'seek',... 'Position', [10,10,60,20]); set(hseek,'Callback',@(src,event)stoprecording(src,event,st)); function stoprecording(src,~,st) val=get(src,'parent') st.icxx(val)=2; st.hz(val)=2; return Thanks in advance. Jose wrote: > how can I return my structure of data once is updating from a callback > function to the main program? You cannot return anything from a callback, so you must use different approaches, such as nested variables, setappdata() / getappdata(), setting the Userdata property of a graphics object, or using global variables. Walter Roberson <roberson@hushmail.com> wrote

Removing a line data while reading a file