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

### Vectorization, array of structures

• Email
• Follow

```Here in the previous example
> data(1).mean = 5;
> data(2).mean = 7;
mean is a scalar number.
c = num2cell([5 7]);
[data.mean] = c{:}; will work

But If mean is a array of dimension( 5,1) and I have matrix ADD of dimension(5,2) to be added to data(1).mean and data(2).mean how should
I Vectoroize the code
```
 0

See related articles to this posting

```You can't add a matrix of dimensions 5 x 2 to a matrix of dimension 5
x 1.  Why do you think that you should be able to?????

data(1).mean = rand(5,2); % mean is a 5x2 array
data(2).mean = rand(5,2);  % mean is a 5x2 array
anotherMeanArray = rand(5,1); % This mean is a 5x1 array
result = data(1).mean + anotherMeanArray

??? Error using ==> plus
Matrix dimensions must agree.

Error in ==> test at 15
result = data(1).mean + anotherMeanArray
```
 0

1 Replies
418 Views

Similar Articles

12/5/2013 6:36:46 PM
[PageSpeed]

Similar Artilces:

Array in Array
Hi guys, I have a question dealing with arrays. Here it go: Suppose A is a 3 by 1 array, I want to assign A (1,1) a 5 by 1 array B, can I do this? How? Thanks in advance! "George " <guanjihou@gmail.com> wrote in message <hutpgd\$km\$1@fred.mathworks.com>... > Hi guys, > > I have a question dealing with arrays. Here it go: > > Suppose A is a 3 by 1 array, I want to assign A (1,1) a 5 by 1 array B, can I do this? How? > > Thanks in advance! Hi George, make A a cell array A = cell(3,1); B = randn(5,1); A{1} = B; Wayne % Use a cell array. A = cell(3,1); A{1} = rand(5,1); % Now look A{1} > > Hi George, make A a cell array > > A = cell(3,1); > B = randn(5,1); > A{1} = B; > > Wayne Thanks Wayne, it really helps. "Matt Fig" <spamanon@yahoo.com> wrote in message <hutqch\$rai\$1@fred.mathworks.com>... > % Use a cell array. > A = cell(3,1); > A{1} = rand(5,1); > > % Now look > A{1} Thanks Matt. "Wayne King" <wmkingty@gmail.com> wrote in message <hutq6d\$f0v\$1@fred.mathworks.com>... > "George

How do I pass structures using a C extension?
Hi. I trying to write an extension module to call some C libraries so I can use them in Python. Several of the library functions pass pointers to structures as arguments. I was thinking that I could create a class for each structure, but I'm not sure how to get the data back and forth. The example the "Extending and Embedding the Python Interpreter" manual has examples of passing strings and ints using PyArg_ParseTupleAndKeywords(), but it's not clear to me if I can even pass structs around like this. I'm just learning how to do extensions, so any help is greatly appreciated. Thanks. ---- Tim Williams You need to check out swig. It is the *only* way to setup a `c' library for use with python. http://www.swig.org/ jw On 14 Mar 2005 05:25:03 -0800, timothy.williams@nvl.army.mil <timothy.williams@nvl.army.mil> wrote: > Hi. > > I trying to write an extension module to call some C libraries so I can > use them in Python. Several of the library functions pass pointers to > structures as arguments. I was thinking that I could create a class for > each structure, but I'm not sure how to get the data back and forth. >

reference to array?
(int (&r)[4]) Reference to array, not array of references (which is not allowed). john Gernot Frisch wrote: > Hope you know what I mean... > > > void Work(int& r[4]) You've declared a four element array of references rather than a refernce to array of 4 ints (which would be int (&r)[4]. However, you don't even need that. C++ inherits the braindamaged array passing behavior from C. A silent conversion of the function type to pointer-to-first element occurs. Your code will work the way you expect if you define the function as: void Work(int r[4]) { Arrays are not passed by value as would be consistant with every other type in the language. The array r is the same as the one in the caller here. Gernot Frisch posted: > Hope you know what I mean... > > > void Work(int& r[4]) > { > r[0]=0; > } > > int main(int, char**) > { > int a[4] > Work(a); > } > Here's some functions that'll alter an array of 4 elements: void Monkey(int* const p_blah) throw() { p_blah[0] = 67; p_blah[1] = -54; p_blah[2] = 76; p_blah[3] = 47; } void Ape(int blah[4]) throw

static array
hi...i am new to c programming....please explain me as to why should an character array be declared as static...thanx...eric dis_is_eagle@yahoo.com wrote: > hi...i am new to c programming....please explain me as to why should > an character array be declared as static...thanx...eric > In what context? The same rules apply for a character array as for any other variable. If the array is in a compilation unit and you don't want it to be visible elsewhere, you declare it static to avoid polluting the global namespace with the array's name. If the array has function scope and you wish the value to be retained between calls, you would declare it static. -- Ian Collins. dis_is_eagle@yahoo.com wrote: > hi...i am new to c programming....please explain me as to why should > an character array be declared as static...thanx...eric In the earlier days, perhaps before C99, a local array could not be initialized unless it was declared as a static one. dis_is_eagle@yahoo.com wrote: > hi...i am new to c programming....please explain me as to why should > an character array be declared as static...thanx...eric One possibility is that you want

array rollup
I need to take a file with multiple records for each person ID and make buckets for each of those records.... so. ID var1 1 7 1 10 1 12 2 8 2 14 3 8 3 20 So I need to take var1 and create 3 variables so that ID is only used once..... ID var1a var1b var1c 1 7 10 12 Help please. I'm going insane with this. I know an Array is probably needed and I'm horrible with those. thanks. Try: Proc sort data = have; by ID; Run; Proc Transpose data = have out = need; by ID; var var1; id whatever you want the columns to be called; Run; -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Hjermstad Sent: Friday, May 18, 2007 3:52 PM To: SAS-L@LISTSERV.UGA.EDU Subject: array rollup I need to take a file with multiple records for each person ID and make buckets for each of those records.... so. ID var1 1 7 1 10 1 12 2 8 2 14 3 8 3 20 So I need to take var1 and create 3 variables so that ID is only used once..... ID var1a var1b var1c 1

Maximun in an array
Hi everyone! A easy question, I think...if I have: a=[2.3 5 9 4.5 1.1] what do I have to do to get the index of the maximun number of the array? In this case it will be: 3 Thank you very much and regards! Javier: <SNIP max-index evergreen... one of the solutions a=[2.3 5 9 4.5 1.1]; [ama,aix]=max(a) us Javier wrote: > > > Hi everyone! > A easy question, I think...if I have: > a=[2.3 5 9 4.5 1.1] > what do I have to do to get the index of the maximun number of the > array? In this case it will be: 3 > Thank you very much and regards! % Find is a very useful function. find(max(a)==a) Wolfgang Garn wrote: > Javier wrote: >> >> Hi everyone! >> A easy question, I think...if I have: >> a=[2.3 5 9 4.5 1.1] >> what do I have to do to get the index of the maximun number of the >> array? In this case it will be: 3 >> Thank you very much and regards! > > % Find is a very useful function. > find(max(a)==a) That does work, but you can get the answer directly from max() which you are calling anyway. [M,index] = max(a); %M is the max value %index is ... well, the index Cheers, David

Array intialization
Hello all, I have very basic question on intializing two dimenstional array. Why cant I initialize a two dimensional int array like the following ? int **intArray = new int[10][20] What is the best way to intialize such array if I need to pass the size as variables, like int [rows][columns], where rows and columns has the size of the array. Thanks in advance Drak -- Use our news server 'news.foorum.com' from anywhere. More details at: http://nnrpinfo.go.foorum.com/ Drak I wrote: > > Hello all, > I have very basic question on intializing two dimenstional array. Why cant I > initialize a two dimensional int array like the following ? > > int **intArray = new int[10][20] > > What is the best way to intialize such array if I need to pass the size as > variables, like int [rows][columns], where rows and columns has the size of the > array. This is a FAQ. > > Thanks in advance > Drak > > -- > Use our news server 'news.foorum.com' from anywhere. > More details at: http://nnrpinfo.go.foorum.com/ -- Karl Heinz Buchegger, GASCAD GmbH Teichstrasse 2 A-4595 Waldneukirchen Tel ++43/7258/7545-0 Fax

annotating \array{}'s
Hi, I'm trying to draw some dynamic programming matrices. The \array{} structure is ideal, except for the fact that I'd like to draw arrows between adjacent cells to illustrate the algorithm. I can't think of any good way to do this. Using arrow fonts makes the particular cell too big, I need it to look pretty. I had a look a pstricks but it seems to be overkill just to add some arrows to a matrix. If anybody has a simple solution, please let me know. Thanks, Adam. -- Dr Adam Spargo High Performance Assembly Group email: aws@sanger.ac.uk Wellcome Trust Sanger Institute Tel: +44 (0)1223 834244 x7728 Hinxton, Cambridge CB10 1SA Fax: +44 (0)1223 494919

What is wrong with my array
I made two-dimensional array. This is my code: LOCAL aMedia AS ARRAY LOCAL dwLen AS DWORD LOCAL n := 1 AS DWORD aMedia := {} AAdd (aMedia,{"100","Text0"}) AAdd (aMedia,{"101","Text1"}) AAdd (aMedia,{"102","Text2"}) AAdd (aMedia,{"103","Text3"}) // here is the rest of the code......... AAdd (aMedia,{"113","Text13"}) AAdd (aMedia,{"114","Text14"}) AAdd (aMedia,{"115","Text15"}) dwLen := ALen(aMedia) // result for dwLen is 16, it is true FOR n := 1 UPTO dwLen ? aMedia [n][1], aMedia [n][2] n++ NEXT The result is: 100,Text0 102,Text2 104,Text4 106,Text6 108,Text8 ........ but it should be: 100,Text0 101,Text1 102,Text2 103,Text3 104,Text4 ...... What I did wrong? Zeljko. Il Tue, 26 Jan 2010 03:15:18 -0800, Zex ha scritto: > I made two-dimensional array. This is my code: > > LOCAL aMedia AS ARRAY