From: Jim on
Walter,

With the larger arrays I basically want to extend the same procedure using the already created function.

So for instance with the smaller arrays:

VAL = [2 5 6 11;...
8 7 9 15 ]

X = [34 87;...
59 79;...
45 22]


The function in the loop reads the input as myfunc_answer2(2, [34;59;45])
myfunc_answer2(8, [87;79;22])
myfunc_answer2(5, [34;59;45])
myfunc_answer2(7, [87;79;22])
.
.
and so on


Now this is only possible since I included the snippet of code you referred to:
%==================
if (xColumn >1)
n=2;
else
n=1;
end
%===================

I used the snippet since I have already I said I wanted to pass in the following manner:

Using X column 1, VAL(1,1)
Using X column 2, VAL(2,1)
Using X column 1, VAL(1,2)
Using X column 2, VAL(2,2)
..
..
and so on


Well in the snippet code I set the condition 1 or 2 , so the passing would read in the following manner,i.e.:

Using X column 1, VAL(n,1) % where the code snipppet allows for when xcolumn=1
% then, n =1.

Using X column 2, VAL(n,1) % where the code snipppet allows for when xcolumn=2
% then, n =2.

..
..
and so on

Now ,the problem i am currently facing is when the input arrrays increase in size.Such as:

VAL = [2 5 6 11;...
8 7 9 15 ;
6 4 36 55]

X = [34 87 65;...
59 79 45;...
45 22 73]


I now to pass in the following manner:

Using X column 1, VAL(1,1)
Using X column 2, VAL(2,1)
Using X column 3, VAL(3,1)
Using X column 1, VAL(1,2)
Using X column 2, VAL(2,2)
Using X column 2, VAL(2,2)
..
..
and so on


Now since in my application these arrays vary in size depnding on the data I use it would not be possible for me to use the following condition which only works when arrays are up to 2 in size.

%==================
if (xColumn >1)
n=2;
else
n=1;
end
%===================


please help
jim
From: Jim on
Hi guys,
jus to let you know the code below works for when arrays are of size 2.
Image Analyst I would like to use the function once in a loop.


%=================================================
clc;
clear all;

X = [34 87;...
59 79;...
45 22]

VAL = [2 5 6 11;...
8 7 9 15 ]


% Now loop through doing all columns of VAL and X
for vColumn = 1 : size(VAL, 2)
for xColumn = 1 : size(X, 2)

if (xColumn >1)
n=2;
else
n=1;
end


fprintf(1, 'Using X column %d, n %d, VAL(%d,%d)\n', xColumn, n, vColumn)
returnValue1 = myfunc_answer2(VAL(n , vColumn), X(:, xColumn))
end
end
%=================================================
From: dpb on
Jim wrote:
> Walter,
>
> With the larger arrays I basically want to extend the same procedure
> using the already created function.
>
> So for instance with the smaller arrays:
>
> VAL = [2 5 6 11;...
> 8 7 9 15 ]
>
> X = [34 87;...
> 59 79;...
> 45 22]
>
>
> The function in the loop reads the input as
> myfunc_answer2(2, [34;59;45])
> myfunc_answer2(8, [87;79;22])
> myfunc_answer2(5, [34;59;45])
> myfunc_answer2(7, [87;79;22])
....

I came to this late but seems more confusing to me the more you write...

The above argument list is

V(1,1), X(:,1)
V(2,1), X(:,2)
V(1,2), X(:,1)
V(2,2), X(:,2)
....

That appears to be (at least superficially) simply a loop on the V array
in internal order alternating the two columns of X.

That would be sotoo

for idx=1:numel(V)
z = func(V(idx), X(:,mod(idx-1,size(X,2))+1);
end

If that doesn't generalize to your other sizes, you need to decipher the
logic that does.

--
From: Jim on
dpb,
thanks mate

jim
From: Jim on
dpb,
thanks again for the working code below. I have another question .

%=============================================
clc;
clear all;

V = [2 5 6 11;...
8 7 9 15 ;
6 4 36 55]

X = [34 87 65;...
59 79 45;...
45 22 73]

for idx=1:numel(V)
z = myfunc_answer2(V(idx), X(:,mod(idx-1,size(X,2))+1))
end

%=============================================

I want to modify the line :
" z = myfunc_answer2(V(idx), X(:,mod(idx-1,size(X,2))+1))"

, so that "V(idx)" can be replaced by any of the 4 columns in V ,i.e

[2;8;6] or [5;7;4] or [6,9,36] or [11 ,15, 55].

An example using any one of these columns would be he last of nagging on this thread.

cheers
jim