f

MATLAB matrix operation

```Hi all:
I am new to MATLAB. I am having a problem in matrix operation using MATLAB. My matrix is of size 3 by 8 the form as follows:

A = [(1,2,0,0,1,2,0,0); (2,1,0,0,2,3,0,0); (3,2,0,0,2,3,0,0)]

what I wanted to do in this matrix is to find the average of values of between zeros in each rows separately and create a separate matrix. I want to exclude all the zeros from the new matrix creating. Then the new matrix will be of size 3 by 2 with form as follows:

B = [(1.5, 1.5); (1.5, 2.5); (2.5, 2.5)]

This is just a toy example. I would like to do it on a much larger matrix of size 442 by 540.

Thanks
Finto
```
 0
fintoa (5)
10/5/2009 9:33:01 PM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader.

9 Replies
532 Views

Similar Articles

[PageSpeed] 32

```Can you expanciate further, if your array is say [1 2 0 1 2 3], what will you expect your answer to be, [1.5 1.5 2.5] or something else like [ 1.5 2.5], I mean if there is one zero what happens?

"Finto " <fintoa@gmail.com> wrote in message <hadomd\$7bh\$1@fred.mathworks.com>...
> Hi all:
> I am new to MATLAB. I am having a problem in matrix operation using MATLAB. My matrix is of size 3 by 8 the form as follows:
>
> A = [(1,2,0,0,1,2,0,0); (2,1,0,0,2,3,0,0); (3,2,0,0,2,3,0,0)]
>
> what I wanted to do in this matrix is to find the average of values of between zeros in each rows separately and create a separate matrix. I want to exclude all the zeros from the new matrix creating. Then the new matrix will be of size 3 by 2 with form as follows:
>
> B = [(1.5, 1.5); (1.5, 2.5); (2.5, 2.5)]
>
> This is just a toy example. I would like to do it on a much larger matrix of size 442 by 540.
>
> Thanks
> Finto
```
 0
10/5/2009 10:50:18 PM
```"Finto " <fintoa@gmail.com> wrote in message <hadomd\$7bh\$1@fred.mathworks.com>...
> Hi all:
> I am new to MATLAB. I am having a problem in matrix operation using MATLAB. My matrix is of size 3 by 8 the form as follows:
>
> A = [(1,2,0,0,1,2,0,0); (2,1,0,0,2,3,0,0); (3,2,0,0,2,3,0,0)]
>
> what I wanted to do in this matrix is to find the average of values of between zeros in each rows separately and create a separate matrix. I want to exclude all the zeros from the new matrix creating. Then the new matrix will be of size 3 by 2 with form as follows:
>
> B = [(1.5, 1.5); (1.5, 2.5); (2.5, 2.5)]
>
> This is just a toy example. I would like to do it on a much larger matrix of size 442 by 540.
>
> Thanks
> Finto

So, what have you tried so far yourself? I suggest you first break down your problem into smaller steps:
1)  how to get the average of a series of numbers "A = [1 2]"
2) how to split an array into smaller ones "B = [1 2 0 [1 2]"

Here is an approach that works only if A is in the above format:

A = [1,2,0,0,1,2,0,0; 2,1,0,0,2,3,0,0; 3,2,0,0,2,3,0,0]
B = reshape(sum(reshape(A.',4,[]))./2,2,[]).'

Jos
```
 0
10584 (930)
10/6/2009 8:55:04 AM
```Ok, my actual problem is related to image analysis. Here, what we got is image of a gel from electrophoresis with 18 lanes in it. My task here is to extract the intensities from the lanes and find the average intensity in each row within each lane. My original image (grayscale) has size of 442 rows and 540 columns. I created a binary matrix by segmenting the original image at intensity level 200 (original image has intensity ranging from 0 to255; intensity above 200 will be 0 and below 200 will be 1). This segmentation pretty much identifies my lanes in the gel. Then, I multiplied the original image matrix with the binary matrix (cell to cell multiplication) so that only the intensity values within the 18 lanes are separated out. I did that. Actually some of the lanes are curved little bit, so the lanes became curved a bit and hence the shape of the matrix.

The example I provided earlier is just a toy. There are situations where just one 0 exist between lanes. Some time, I think we need to correct the binary image manually. Even after correcting, the lanes will be still tilted. My task is to find mean intensity for each row of pixel in each lane.

If anybody got a better alternative, please let me know

Thanks
Finto
```
 0
fintoa (5)
10/6/2009 5:45:21 PM
```One solution:

% Data
>> A = [1,2,0,0,1,2,0,0; 2,1,0,0,0,3,0,0; 3,2,2,3,0,0,0,0]

A =

1     2     0     0     1     2     0     0
2     1     0     0     0     3     0     0
3     2     2     3     0     0     0     0

% Need SplitVec from FEX
>> s=@(k) SplitVec([A(k,:)~=0; A(k,:)].', 1, @(x) mean(x(:,2)), 'Uniform', 1).';
>> c=arrayfun(@(k) nonzeros(s(k)), 1:size(A,1), 'Uniform', 0);

% Check the results
>> c{:}

ans =

1.5000
1.5000

ans =

1.5000
3.0000

ans =

2.5000

% Bruno
```
 0
b.luong5955 (6401)
10/6/2009 6:14:02 PM
```Link to SplitVec: http://www.mathworks.com/matlabcentral/fileexchange/24255

Bruno
```
 0
b.luong5955 (6401)
10/6/2009 6:17:19 PM
```Hi,

Thanks for the help.

I tried to run the toy example provided by you in matlab. I am getting an error message. Cold you please explain this to me:

?? Error: "SplitVec" is not the name of a function nor a variable,
but is used in an anonymous function either at the prompt or in the argument of EVAL.

Thanks
Finto

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hag1jf\$i08\$1@fred.mathworks.com>...
> Link to SplitVec: http://www.mathworks.com/matlabcentral/fileexchange/24255
>
> Bruno
```
 0
fintoa (5)
10/6/2009 6:55:19 PM
```"Finto " <fintoa@gmail.com> wrote in message <hag3qn\$d8o\$1@fred.mathworks.com>...
> Hi,
>
> Thanks for the help.
>
> I tried to run the toy example provided by you in matlab. I am getting an error message. Cold you please explain this to me:
>
> ?? Error: "SplitVec" is not the name of a function nor a variable,
>  but is used in an anonymous function either at the prompt or in the argument of EVAL.

Not sure, does SplitVec is on a Matlabpath?

What if you type

>> which SplitVec

Bruno
```
 0
b.luong5955 (6401)
10/6/2009 7:08:02 PM
```Hi,

The splitVec function is running. Now the problem is arrayfunc which is not recognizing by matlab version which I am using (MATLAB 7). Is there any way that I can get around with this function.

Thanks
Finto

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hag4ii\$2j2\$1@fred.mathworks.com>...
> "Finto " <fintoa@gmail.com> wrote in message <hag3qn\$d8o\$1@fred.mathworks.com>...
> > Hi,
> >
> > Thanks for the help.
> >
> > I tried to run the toy example provided by you in matlab. I am getting an error message. Cold you please explain this to me:
> >
> > ?? Error: "SplitVec" is not the name of a function nor a variable,
> >  but is used in an anonymous function either at the prompt or in the argument of EVAL.
>
> Not sure, does SplitVec is on a Matlabpath?
>
> What if you type
>
> >> which SplitVec
>
> Bruno
```
 0
fintoa (5)
10/12/2009 5:35:23 PM
```"Finto " <fintoa@gmail.com> wrote in message <havpcr\$c8r\$1@fred.mathworks.com>...
> Hi,
>
> The splitVec function is running. Now the problem is arrayfunc which is not recognizing by matlab version which I am using (MATLAB 7). Is there any way that I can get around with this function.
>

For loop.

Bruno
```
 0
b.luong5955 (6401)
10/13/2009 5:56:02 AM

Similar Artilces:

MATLAB talking to MATLAB?
For my project, I need to have a client program (MATLAB executable) talking to a server program (also MATLAB executable) to query data. Is there any easy way to accomplish that? I appreciate any help that I can get on that. Thanks. Cheers, Hoi Oops, I forgot to mention. There are multiple clients querying the server, so I guess serial objects + remote serial port wouldn't work. "Hoi Wong" <wonghoi.ee@gmail.com_> wrote in message news:f3ald6\$gg4\$1@news.Stanford.EDU... > For my project, I need to have a client program (MATLAB executable) > talking to a ser...

Run Matlab ... from Matlab
Hello, Is there any limitation to run Matlab from Matlab, as a system command, on Linux platforms ? I tried to start Matlab, both using the ! syntax (!matlab&) or the system command (system('matlab&')), the Matlab splash screen appears, but the new Matlab session closes rapidly . When I do the same with a script of mine (system('matlab -r "myscript"&')), my script is being executed, but Matlab finally crashes . If I remove the &, it works well, but the first Matlab session is blocked till I close the second one . I run Matlab on a Linux 64bits pla...

Does Matlab have symbolic operations for matrix?
Hi all, I need to reduce some expressions in complicated matrix forms... Does Matlab have such a capability in reducing expressions symbolically for matrices? Thanks a lot! In article <duqi2b\$qd7\$1@news.Stanford.EDU>, "gino" <loseminds@hotmail.com> wrote: > Hi all, > > I need to reduce some expressions in complicated matrix forms... > > Does Matlab have such a capability in reducing expressions symbolically for > matrices? > > Thanks a lot! -------------------- With my version of the Symbolic Math Toolbox (4a), it is done with: M = ...

How to transfer a VC matrix to matlab workspace and manipulate it under matlab GUI ?
I would like to transfer a VC matrix to matlab main program workspace, than i can observe it by Matlab array editor, or directly manipulate it under matlab GUI. I tried engdemo.c, but i found that under this mode, matlab runs on background, there is no matlab main program GUI, I can only excute matlab command on C, and see result, like ploting. how should this be done ? Thank you so much. "KS " <CHH@itri.org.tw> wrote in message <hs008g\$256\$1@fred.mathworks.com>... > I would like to transfer a VC matrix to matlab main program workspace, > &...

Slow matrix operations in Matlab 7
Hello, Can anyone explain why in the example below computation of X^.2 is 30 times faster than X.^3? Obviously, there should be a difference but not that huge... >> X=rand(500,500); >> tic; for i=1:1000; Y=X.^2; end; toc; Elapsed time is 4.696091 seconds. >> tic; for i=1:1000; Y=X.^3; end; toc; Elapsed time is 154.175887 seconds. Thanks! Alex Alexander Statnikov wrote: > Hello, > > Can anyone explain why in the example below computation of X^.2 is 30 > times faster than X.^3? Obviously, there should be a difference but > not that huge... > > >>...

How the matrix operation speed up a function in matlab
I want to know how matrix manipulations speed up a function or reduce the execution time in matlab. The time is reduced by avoiding the no.of iterations or loops in that particular function or by matrix operations.if so how? Govind m-tech AVVP ...

An inbuilt Matlab command for matrix operation
Hi, Can anyone please tell me the command in Matlab that will take a 1xNxM matrix as the input and will return the NxM part. Thanks Ram Ram wrote: > > > Hi, > Can anyone please tell me the command in Matlab that will take a > 1xNxM matrix as the input and will return the NxM part. > > Thanks > > Ram I'm pretty sure there is. look up permute and reshape. Hopefully following the see also will lead you in the right direction. John Creighton wrote: > > > Ram wrote: >> >> >> Hi, >> Can anyone please tell me the command in Matlab th...

matlab operators
Matlab provides a mechanism to overload operators such as +.-.^. etc. What I'd like to do is define a behavior for underscore '_' to act like the '@' symbol. That is @ makes a new function handle, and I'd like '_' to make a new member of a new class that I'm working on (an index_handle of sorts for tensor math). Does anyone know if matlab allows something like this? In article <ef1c496.-1@webx.raydaftYaTP>, "Nathan Strange" <nstrange@gmail.com> wrote: > Matlab provides a mechanism to overload operators such as +.-.^. etc. > Wh...

Matrix, matlab
Hello, a)I need to create an M*M matrix of all zeros, except for one row on ones in the center. M in the matrix will vary from 16, 32,64,128. b)I need to repeat the above for two rows of ones.Here the two rows of ones should be seperated by four rows of zeros. Thank you, athina shah wrote: > Hello, > > a)I need to create an M*M matrix of all zeros, except for one row on > ones in the center. > > M in the matrix will vary from 16, 32,64,128. it will be pretty difficult, since you can not create the rows number 7.5, 15.5 and so one > b)I need to repeat the above ...

DLL creating by Matlab for Matlab
I would like to know if it is possible to convert several M-files into one DLL with Matlab (by using mcc or mex or other functions) and use this DLL with Matlab. How can I do that? I could create DLL with mcc -l xxx.m but I can't use this DLL with Matlab (error: "??? The function, script or class xxx cannot be indexed using {} or . indexing.") I have a project on Matlab with just M-files and I want to give this project to someone who want to use it on Matlab too, but I don't want to give him the source M algorithms. Moreover, I don't want to have an executable....

Matlab OR operator
I cannot figure out logic beyond handling empty values by OR operator. In the example below the first expression evaluates into false while the second into true. Any help is greatly appreciated, Kirill s = []; if s == 't' | isempty(s) disp('true'); else disp('false'); end if isempty(s) | s == 't' disp('true'); else disp('false'); end false true >> Kirill wrote: < SNIP ... problems with the logics of emptiness .. this will hopefully clarify things: s = [] s == 't' [] | isempty(s) if [] disp ('true'...

Spawning matlab from within matlab
Hello all, I would like to spawn multiple matlab processes from an '.m' script. Meaning, run an m-file from a 'parent' Matlab that launches, say, 8 more 'children' matlab processes. I'd like to do it in such a way that the same m-file in the 'parent' is able to close down, or kill, all the 'children' processes. Any suggestions? Joe ...

Matlab plots outside Matlab
I'm making an end-user application where I would like to use Matlab functionality both for calculation and plotting. Matlabs GUI builder guide does not satisfy my needs (no support for f.ex. internal frames and other nescessities), so I'm planning to compile my Matlab code and use other API (Java, QT or something) for GUI. My problem is then, that I loose access to the neat plotting commands availible under matlab GUI... Is there a way of integrating Matlabs plot functionality into another GUI system? - has it been done? - I appreciate any response! - P�l Berge ...

Calling Matlab in C in Matlab
Hi everybody! My problem can be described as follows. I have a tool in Matlab that requires calling an optimisation algorithm in C. This algorithm consists of several C-files, one of which contains the function to be minimised (CFUNCTION), and another is the main algorithm file (CMAIN). Now what I want to do is to call Matlab from CFUNCTION or CMAIN and specify my custom function (MFUNCTION) to be minimised. So, I'm calling Matlab from C from Matlab. I'm a newbie in C and MEX files. Should I rewrite CMAIN as a MEX file and include CFUNCTION in this and then use mxCallMATLAB? Or can...

from Delphi to matlab and matlab to delphi
How to send vars from Delphi to Matlab ? and viceverse, from matlab to delphi ? thanks, it is dificult, and not found answers in the internet. jairo serrano wrote: > > > How to send vars from Delphi to Matlab ? and viceverse, from matlab > to delphi ? thanks, it is dificult, and not found answers in the > internet. When I want to use Matlab variables in another program, I write them to file. You can use comma separated files (csv). Try: > help csvwrite > help dlmwrite Works fine for me. Hope this helps, Niels jairo serrano wrote: > How to send vars from Delphi to...

Calling Compiled MATLAB from MATLAB
Hello everyone, How do I compile MATLAB M files into a form that can then be called from within the MATLAB interpreter? A roundabout way would seem to be to (somehow) Turn the matlab code into C (I think mcc does this), then compile this C code into MEX format and call that. Is there an easier way? I have the MATLAB compiler, so I just need to know what to do with it to get this to work. Thanks in advance, Sina sina.tootoonian wrote: > > > Hello everyone, > > How do I compile MATLAB M files into a form that can then be called > from within the MATLAB interpreter? A round...

Matrix in MatLab
Does anybody knows, how to delete repeated strings in Matlab Matrix? Have Matlab some special function? I don't want to write it by myself :D Help me, please. ...

matlab operation
how to write the coding for A &#8898; B? "Ng Pong Li" <ngpl0087@gmail.com> wrote in message <h7odbb\$r43\$1@fred.mathworks.com>... > how to write the coding for A &#8898; B? >>doc intersect "Wayne King" <wmkingty@gmail.com> wrote in message <h7oe5j\$n02\$1@fred.mathworks.com>... > "Ng Pong Li" <ngpl0087@gmail.com> wrote in message <h7odbb\$r43\$1@fred.mathworks.com>... > > how to write the coding for A &#8898; B? > > >>doc intersect >> C=intersect(SE,B); ??? Error using ==> int...

Matlab engine with matlab R2010b
Hello All, I'm working with an aplication that use the matlab engine. I made the C++ program and it is working well in my pc with matlab 2007b, but the same very basic program shows an error when I tried to compile it in a pc with matlab R2010b. The error is about the icuuc32.dll. ¿Why is asking this DLL? How can I solve this?. Thanks¡ ...

matlab to matlab remote execution
Hi I have two win PCs running matlab 7. One is slow and other is a high spec fast PC. They are connected to LAN. The directory on fast PC where all matlab work takes place has been mounted as a drive on slow PC. Hence this directory on fast PC can be accessed from slow PC's matlab session. I want to let the user on slow PC run some computationally intense M scripts in his matlab session but execute them on fast PC. I tried usual unix like method. First installed telnet server on fast PC. Then used telnet client on slow PC to log on fast PC. If I attempt to start matlab in slow PC telnet ...

Matlab matrix
How I can put time value like 10:23:34 in a matrix cell. Like below: a(1,2)= 10:23:34 Regards "M" wrote in message <kehbrk\$3pp\$1@newscl01ah.mathworks.com>... > How I can put time value like 10:23:34 in a matrix cell. Like below: > a(1,2)= 10:23:34 One approach is to use a cell array and have the entry be a string. E.g., a = cell(1,2); a{1,2} = '10:23:34'; James Tursa On 2/1/2013 3:46 PM, James Tursa wrote: > "M" wrote in message <kehbrk\$3pp\$1@newscl01ah.mathworks.com>... >> How I can put time value like 10:23:34 in a ...

matlab in JAVA or java in MATLAB?
Hi guys I am now experencing a great difficulty in the interation between java and matlab. I have an objective function written in JAVA with has method return an numerical number, i call it 'profit'. The nature of this obtive function (ObjFun.java) is that it takes an parameter input, say C, with different C value, the returned profit value is different. Eventually I want to find the optimized C value which produce the maximun profit (C will be under constrains). Initially I want to use linprog or fminsearch in matlab. So I tried the command in matlab that excutes my ObjFun.ja...

parallel matlab
Hi all, I'm going to work on a project involving a parallel version of MATLAB - I'm aware of various efforts like MATLAB-*P and so on Right now I need to read up on some material regarding MATLAB internals eg: How are the ATLAS(or is it BLAS) routines called in MATLAB? How does MATLAB's C code store information in memory, cache'ing etc? How is one to get at those? Do you know of any suitable reference(s)/resource(s)? Thank you very much, Aravind ...

Matlab
Hello , I'm a new user in Matlab. So should you advise matlab notes , documentation please ? <azatserver113@gmail.com> wrote in message news:7b4e75e2-40c6-43bb-acc6-2553123ba649@googlegroups.com... > Hello , > > I'm a new user in Matlab. So should you advise matlab notes , > documentation please ? > At the MATLAB command prompt type this command: doc This will show the documentation included as part of your installation. I recommend reading through the Getting Started section of the MATLAB documentation first, and executing the examp...

Web resources about - MATLAB matrix operation - comp.soft-sys.matlab

United States Special Operations Command - Wikipedia, the free encyclopedia
The United States Special Operations Command ( USSOCOM ) is the Unified Combatant Command charged with overseeing the various Special Operations ...

Federal government to review Australian Institute of Sport operations five months from Rio Olympics
AOC president John Coates has criticised the Australian Sports Commision after a change in policy left the body with 560 public servants and ...

Missing NSW swimmer sparks search operation
A man last seen in 'serious distress' is feared missing in dangerous surf in Sydney's northern beaches.

Federal government to review Australian Institute of Sport operations five months from Rio Olympics
AOC president John Coates has criticised the Australian Sports Commision after a change in policy left the body with 560 public servants and ...

Turkey, Saudi Arabia could launch 'ground operation' against Islamic State in Syria, Foreign Minister ...
Turkey and Saudi Arabia could launch a ground operation against Islamic State militants in Syria, Turkey's Foreign Minister says.

Iluka suspends operations at South Australian zircon mine
Operations at one of the world's largest zircon projects will be suspended for up to two years in a bid to improve challenging market dynamics. ...

Apple pulls back the curtain on its secretive chip development operation
The engineering team responsible for the custom silicon that powers hundreds of millions of Apple's iOS devices is the latest beneficiary of ...

Equinix Slips: Q4 Rev Beats, Funds from Operations Misses
... center hosting provider Equinix (EQIX) this afternoon reported Q4 revenue that topped analysts’ expectations, but delivered funds from operations, ...

The People's Bank of China Moves to Daily Open-Market Operations
Bloomberg The People's Bank of China Moves to Daily Open-Market Operations Bloomberg China's central bank will conduct open-market operations ...

Buchanan: San Bernardino Attacker’s Phone Should Be Accessed In ‘A Single-Off Operation’
Buchanan: San Bernardino Attacker's Phone Should Be Accessed In 'A Single-Off Operation'

Resources last updated: 2/24/2016 9:03:00 AM