|
"us " <us@neurol.unizh.ch> wrote in message <gqb82u$hig$1@fred.mathworks.com>...
> "Jose"
> > It works well, but I would like to get a definitelly matrix z avoiding loops:
> > I think, one way to do it, for example the first two columns:
> > x(1,:)-a(1,:) x(1,:)-a(2,:)
> > x(2,:)-a(1,:) x(2,:)-a(2,:)
> > x(3,:)-a(1,:) x(3,:)-a(2,:)
> > can be described with:
> > x-repmat(a(1,:),nrp,1) % first column
> > x-repmat(a(2,:),nrp,1) % second column
> > But, how I can built a z matrix with N columns?
> > I would like to write down these two columns in a more general form to N columns.
> > Some idea...
>
> did you even bother to consider to bother to look at what was shown to you...
> apparently not...
> what happens if you change the vars
> NRV
> NRP
> in the above solution...
> your way of posting in this NG is not boding well...
>
> us
Hello us, I asked you a simple question in message 10, and you did not answer me.
I was cheking your stock function to do it, and it is right.
I changed the values of the variables nrp and nrv and this is correct...but...again I ask you:
what happens
if you want to play with the full matrix r:
Let me explain you it better with this piece of code:
clc
clear all
nrp=5;
nrv=3;
v1=ceil(10*rand(nrp,2))
v2=ceil(5*rand(nrv,2))
[ix2,ix1]=meshgrid(1:nrv,1:nrp);
r=arrayfun(@(x,y) v1(x,:)-v2(y,:),ix1,ix2,'uni',false)
r{1,1}
r{2,1}
r{3,1}
r{4,1}
r{5,1}
Results:
v1 =
5 1
10 9
8 10
10 7
7 8
v2 =
4 1
2 4
4 1
r =
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
ans =
1 0
ans =
6 8
ans =
4 9
ans =
6 6
ans =
3 7
It works really well,and thanks for that, but my question is:
I want to work with r like a matriz with values in it.
In your way, only I obtain r like that:
r =
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
[1x2 double] [1x2 double] [1x2 double]
And efectivelly, if I write every element individually like r{1,1}, r{2,1}........
I obtain the perfect correct value, but I like to play with the full matrix
not with individual values, and I suppose the best way to do it is using repmat or repshape.
For this reason, I asked to the community again other way to do it, because you do not answer me my question in message 10.
Thanks for your help, anyway, it was good way to do it, but not the way I am interested to.
My apologize if you thought I did not check your form to do it,
I did it and I tested it.
Jose.
|