f

#### How to put the elements of a matrix to specific locations to a larger matrix in MATLAB?

```I have a matrix of larger 4x4, and I have a smaller matrix of 2x2 and their respective row and column positions in the larger matrix. I want to assign the elements of the smaller matrix to the larger matrix on that specific row and column positions with out using any loop, I am doing so,

im = zeros(4,4)
r=[1 2; 3 4]
c=[1 2; 3 4]
indices = sub2ind(size(im),r,c);
im1=ones(2,2)
im(r, c)=im1(:)
but it gives exception of,
"Subscripted assignment dimension mismatch".

any help in this regard will be appreciated.
```
 0
javed
8/22/2014 12:20:16 PM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader.

2 Replies
414 Views

Similar Articles

[PageSpeed] 48

```On 8/22/14, 2:20 PM, javed iqbal wrote:
> I have a matrix of larger 4x4, and I have a smaller matrix of 2x2 and their respective row and column positions in the larger matrix. I want to assign the elements of the smaller matrix to the larger matrix on that specific row and column positions with out using any loop, I am doing so,
>
> im = zeros(4,4)
>     r=[1 2; 3 4]
>     c=[1 2; 3 4]
>     indices = sub2ind(size(im),r,c);
>     im1=ones(2,2)
>     im(r, c)=im1(:)
> but it gives exception of,
> "Subscripted assignment dimension mismatch".

Try

im(indices)=im1(:)

HTH,

Christopher

```
 0
Christopher
8/22/2014 12:52:19 PM
```Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <53F73D03.7060102@mathworks.com>...
> On 8/22/14, 2:20 PM, javed iqbal wrote:
> > I have a matrix of larger 4x4, and I have a smaller matrix of 2x2 and their respective row and column positions in the larger matrix. I want to assign the elements of the smaller matrix to the larger matrix on that specific row and column positions with out using any loop, I am doing so,
> >
> > im = zeros(4,4)
> >     r=[1 2; 3 4]
> >     c=[1 2; 3 4]
> >     indices = sub2ind(size(im),r,c);
> >     im1=ones(2,2)
> >     im(r, c)=im1(:)
> > but it gives exception of,
> > "Subscripted assignment dimension mismatch".
>
> Try
>
> im(indices)=im1(:)
>
>
>
> HTH,
>
> Christopher

Thanks Christopher,

it can be acheived using the syntex
im(indices)=im1;
```
 0
javed
8/25/2014 7:59:09 AM

Similar Artilces:

how can I calculate specific elements in Matlab matrix
I have a matrix: ================== x=1.0 A=[1, x, x^2+1 x, 5*x, x^3 7*x, 3, cos(x)]; ==================== for example, I only want to calculate specific elements in A, say when x=1.0,need calculate A(1,2) and A(2,3), while when x=2.1, need calculate A(2,3), A(1,3). Is there any command in matlab can do this or some other way instead of calculating all the elements then pick the specific elements? Thanks!!! "Jim Chen" <yzarcc@hotmail.com> wrote in message news:eed097c9.0409210906.2b4168cd@posting.google.com... >I have a matrix: > ================== > x=1.0 >...

prevent MATLAB from showing matrix's elements when the mouse is beside that matrix's name
How can I prevent MATLAB from showing matrix's elements when the mouse is beside that matrix's name? Thanks Zeinab Ghofrani On Sun, 30 May 2004 01:52:31 -0400, "Zeinab Ghofrani" <zghofrani@yahoo.com> wrote: >How can I prevent MATLAB from showing matrix's elements when the >mouse is beside that matrix's name? Open the preferences. Goto editor/debugger / Display and deselect "enable datatips in edit mode". Lars Lars Gregersen COMSOL A/S http://www.comsol.dk ...

About the element of Matrix in Matlab
I have a difficulty in using Matlab to create a matrix. The matrix have its element is a random function of time-varying valuable t such as Gaussian or Sin. When t changes the matrix is changed and my system will use this matrix to calculate. My example: A is a square matrix 3,3. A(1,1) = 2 sin(t), A(1,2)=1 sin(t), A(1,3)= 3cos(t). A(2,1) = 1 cos(t),A(2,2) = 3sin(t), A(2,3) = 2cos(t). A (3,1)= 0.5sin(t),A(3,2) = 1.5sin(t),A(3,3)=3sin(t). A will be changed when t is running. So how I can matrix A to calculate. Please help me about Matlab code. Thanks. "Viet Dang" <muapho...

matrix with matrix for each element
Hi, I am trying to create a matrix which has a matrix as each element e.g.: h=[1:3]' h(1)=[1,2;3,4] I then get this message which is understandable: ??? In an assignment A(I) = B, the number of elements in B and I must be the same. Is there a way to do this though? Thanks in advance. "Dave Brackett" <davebrackett@hotmail.com> wrote in message <g5i9f9\$eoo\$1@fred.mathworks.com>... > Hi, I am trying to create a matrix which has a matrix as > each element e.g.: > > h=[1:3]' > h(1)=[1,2;3,4] > > I then get this message which is understan...

About the element of Matrix in Matlab #2
I have a difficulty in using Matlab to create a matrix. The matrix have its element is a random function of time-varying valuable t such as Gaussian or Sin. When t changes the matrix is changed and my system will use this matrix to calculate. My example: A is a square matrix 3,3. A(1,1) = 2 sin(t), A(1,2)=1 sin(t), A(1,3)= 3cos(t). A(2,1) = 1 cos(t),A(2,2) = 3sin(t), A(2,3) = 2cos(t). A (3,1)= 0.5sin(t),A(3,2) = 1.5sin(t),A(3,3)=3sin(t). A will be changed when t is running. So how I can matrix A to calculate. Please help me about Matlab code. Thanks. you can use a loop and a timer to...

How to reduce a sigular matrix to a full rank matrix in matlab
reduce 80*80 sigular matrix to a 72*72 full rank matrix oasis wrote: > reduce 80*80 sigular matrix to a 72*72 full rank matrix delete linear dependent rows/columns steffen --=20 Steffen Brueckner brueckner@sbrs.net http://www.sbrs.net ISD Uni Stuttgart How to find the linear dependent column/row > How to find the linear dependent column/row i am not sure why you want to do that, one way would be : [U,S,V]=svd(A80); idx=find(diag(S)>1e-15); A72=U(idx,idx)*S(idx,idx)*V(idx,idx)'; but i think you should have a careful look to orth, null and related functions before you do ...

Find numbers and location in a matrix , and put it into new matrix
Hi! I am trying to make a function which is to find a certain number, or numbers above a threshold number, in a given matrix of unknown size. Preferably without any other function then if,else,while,for. function search = searchMatrix(matrix) search = []; [r c] = size(matrix); for i = 1:r for j = 1:c if (matrix(i,j) >= 2000) search = matrix(i,j) && i && j; end end end But I would like the numbers, and the location of the numbers to be put into a new matrix "search" with each new row correspondi...

Inserting a smaller matrix into a specific position in a larger matrix
Hi guys, I am writing an image registration package, and hence need to insert an image (matrix of doubles) into a larger matrix at a specific position as calculated by my algorithm. I tried using matrix indexing to insert, but just got 'array subscript mismatch' errors, so i am using a loop to individually allocate pixels and it just eats up CPU time. What i want is something like: insert_row % Row insertion position insert_col % Column insertion position sub_rows % Rows in smaller matrix sub_cols % Columns in smaller matrix larger_matrix( insert_row : insert_row + sub_r...

How matlab accesses the elements of a vector/matrix
I was wondering if anybody know how matlab accesses the elements of a vector/matrix. Will it take matlab longer time to access two nonproximate elements of a vector than two proximate ones ? Let's say I were to access the elements for each iteration in a for loop "for i=1:n ....", where n is a large number. Is it at all worth thinking about making some structure such that the elements accessed in each iteration becomes proximate in some way ? Or will this not be important for the speed of matlab ? Sincerely, -Stein "Stein Grongstad" <sgrongst@math.uio.no> wr...

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 ...

Matrix of matrix
Hi everbody. First of all, I apologize for my English, so please be indulgent with me if my sentences are not grammatically correct. I have some trouble with MATLAB. I have some data in txt files that I catch like that : MFS93A1 = textread('Z:/Fichiers/MFS93.A1.txt','','headerlines',1); MFS93B1 = textread('Z:/Fichiers/MFS93.B1.txt','','headerlines',1); MFM77A1 = textread('Z:/Fichiers/MFM77.A1.txt','','headerlines',1); MFM77C1 = textread('Z:/Fichiers/MFM77.C1.txt','','headerlines',1); Then, in or...

Matrix element to Matrix element-range mutiplication
Greetings to you all! I have two matrices: Matrix_W=[P,N] Matrix_X=[4*P,N] I want to perform a multiplication between the [i,j]-th elements of W and the [4*i-3 : 4*i , j]-th ranges of elements of X. and end up with a [4*P,N] matrix. I there a way to quickly perform such an operation without having to endure the overkill of a double for-loop? Thank you in advance. "George Antonopoulos" <georanto@gmail.com> wrote in message news:htj3cp\$har\$1@fred.mathworks.com... > Greetings to you all! > > I have two matrices: > Matrix_W=[P,N] > Matrix_...

matrix in matrix (?)
Hi, I need help! I want to construct a matrix 10x10 where every element is a matrix ?x2. After, I need to extract the ?x2 matrix by the 10x10. how to make that? mirus wrote: > Hi, I need help! > > I want to construct a matrix 10x10 where every element is a matrix > ?x2. > > After, I need to extract the ?x2 matrix by the 10x10. > > how to make that? have a look at cell arrays. they provide the possibility to store arbitrary data in an array like fashion. michael Michael Wild wrote: > mirus wrote: >> Hi, I need help! >> >> I want to constru...

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 ...

Web resources about - How to put the elements of a matrix to specific locations to a larger matrix in MATLAB? - comp.soft-sys.matlab

List of Massachusetts locations by per capita income - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

‘Tom Clancy’s The Division’ location exclusions, map size and details revealed
More details for “The Division” have been rolled out before the official beta starts.

Walmart To Shutter 154 U.S. Stores, Including One Ohio Location
Walmart is closing 269 stores, more than half of them in the U.S. and another big chunk in its challenging Brazilian market.

Bivid Location-Based Social Networking App Launches on iOS
Following a beta launch of its platform in September 2015, Bivid has officially launched its location-based social networking app on iOS. Bivid ...

House of Yes officially open in new Bushwick location; new nightclub being planned for the same area
the new House of Yes (photo via Facebook) After a long road to finding a new venue, performance collective House of Yes's new space is finally ...

Hyatt hackers snagged credit card numbers from 250 locations
Hackers managed to compromise payment cards used at 250 Hyatt Hotels locations in around 50 countries after infecting the company's payment processing ...

Nest Thermostats Have Been Leaking Users’ Home Locations Over WiFi
... at Princeton University pointed out a problem that should terrify most Nest users: their thermostats have been broadcasting their location, ...

L.A. On-Location Production Grew In 2015 As Tax Credits Kicked In
On-location filming in Los Angeles grew 1.3% in 2015 compared with the year before thanks to a surge in TV production. The gains, reported today ...

Two Boots Prepares for a Midtown Move — Plus More New Locations
... Hartman confirms that the pizzeria will be moving to 337 Lexington Avenue at the beginning of March. When it opens, the Lexington Avenue location ...

All Chipotle Locations Will Close For A Food Safety Meeting On February 8
Following a slew of outbreaks caused by food-borne illnesses, Chipotle is making food safety its priority. After months of food poisoning reports ...

Resources last updated: 1/26/2016 2:26:38 PM