From: roya olyazadeh on
"Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hstlbo$p3d$1(a)fred.mathworks.com>...
> "roya olyazadeh" <roya2543(a)gmail.com> wrote in message <hstkfj$sbc$1(a)fred.mathworks.com>...
> > My mistake... Q1 must be like this :
> > >
> > > In this example i = 1 , 3,4
> > >
> > > So Q1 must be something like this :
> > >
> > > 0 0 0 0 0 0
> > > 0 2 0 0 3 4
> > > 0 0 0 0 0 0
> > > 0 0 0 0 0 0
> > > 0 4 0 0 5 6
> > > 0 7 0 0 8 9
>
> Easy enough with the right tools:
>
> % data
> Q = [2 3 4 ; 4 5 6 ; 7 8 9] ;
> ix = [1 2 2] ; % your ix was defined with reference to the outcome
> % engine
> Q1 = insertrows(Q,0,ix-1) % note the -1
> Q1 = insertrows(Q1.',0,ix-1).' % note the transpose twice
>
> INSERTROWS can be found here:
> http://www.mathworks.com/matlabcentral/fileexchange/9984
>
> hth
> Jos
This did not work for my project. I can not change ix manually..
I have ix= [ 1 3 4 ]
and exactly I want to add first row 1 column 1 then row 3 column 3 and then 4
From: Jos (10584) on
"roya olyazadeh" <roya2543(a)gmail.com> wrote in message <hsu998$e8c$1(a)fred.mathworks.com>...
< SNIP ... suggestion of using INSERTROWS by Jos ...

> This did not work for my project. I can not change ix manually..
> I have ix= [ 1 3 4 ]
> and exactly I want to add first row 1 column 1 then row 3 column 3 and then 4

I see. Here is another solution:

% data
Q = [2 3 4 ; 4 5 6 ; 7 8 9] ;
ix = [1 3 4] ;
% engine
Q2 = ones(numel(ix) + size(Q)) ;
Q2(ix,:) = 0 ;
Q2(:,ix) = 0 ;
Q2(Q2==1) = Q
% result
% 0 0 0 0 0 0
% 0 2 0 0 3 4
% 0 0 0 0 0 0
% 0 0 0 0 0 0
% 0 4 0 0 5 6
% 0 7 0 0 8 9

hth
Jos