From: dpb on
Jim wrote:
> 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

Well, again, the more you write (instead of showing either the logic
behind the request or a list of the expected output) the less clear the
request becomes.

That doesn't seem consonant w/ the previous, but it would seem you would
simply change the loop index to run over the column desired instead of
the numel().

--
From: us on
"Jim " <iwonder26(a)gmail.com> wrote in message <i3mtel$5eb$1(a)fred.mathworks.com>...
> 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

what have YOU done so far to solve YOUR particular problem...
show CSSM your thoughts in plain ML language...

us
From: Sean on
"Jim " <iwonder26(a)gmail.com> wrote in message <i3iqad$fd$1(a)fred.mathworks.com>...
> Hello guys,
>
> I am coding a rather large application and am faced by another stumbling block and need your help and expertise.
>
> Firstly, as follows is the function:
>
> %======================================
> function Return = Return_answer (x, X)
> Return = -(x * X(1,1) + X(3,1)) / X(2,1);
> %======================================
>
> Now in my application I am faced with the multiple values in the 'x' and 'X' variables, hence I'll need to do some looping.
>
> So, I will begin explaining my issue:
>
> VAL = [ 2 5 6 11;
> 8 7 9 15 ]
>
> xmin = VAL(1)
> ymin = VAL(2)
> xmax = VAL(3)
> ymax = VAL(4)
>
> Now, my first problem here is that with the matrix 'VAL' I want to distinguish 'xmin' , 'ymin' , 'xmax' and 'ymin' for each row in VAL.
>
> I am given in my application 'X' to be defined as:
>
> X = [34 87;
> 59 79;
> 45 22]
>
> This is where my second problem comes in. In the function 'Return' , X is supposed to be in the form X = [ 34; 59 ;45 ] and X = [87 ; 79; 22].
>
> So, finally , to get my final result, I use the function in code as follows:
>
> %==============================================
> X = [ 34; 59 ;45 ];
> VAL = [ 2 5 6 11];
>
> xmin = VAL(1)
> ymin = VAL(2)
> xmax = VAL(3)
> ymax = VAL(4)
>
> Return = Return_answer(xmax, X)
> %==============================================
>
> The return answer is
>
> Return = -4.22033898305085
>
> I am new to Matlab and coding in general and not too sure on looping, So basically, I would like to get a return answer using looping.
>
> With the other set of input values into the function as follows:
>
> X = [ 87; 79 ; 22 ];
> VAL = [ 8 7 9 15];
>
> The return answer is
>
> Return = -10.1898734177215
>
> To conclude, I want in the end to get a final output answer of the form:
>
> Return =
> -4.22033898305085
> -10.1898734177215
>
> If any of you can help, please do, I'm in strife.
>
> jimmy


A couple of hints to look at:
-linear indexing:
ymin = VAL(2) what you expect? what about xmax or ymax?

for whole row indexing:
new_values = matrix(1,:);
for whole column indexing:
new_values = matrix(:,1);

I would recommend doing some of the MATLAB beginner tutorials.