Passing the values in a fixed format

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing the values in a fixed format

GK19
I have 2 arrays

Position = {"ITC""VTC""KZT"};

Direction = [0.34 0.56 0.99]

abc = interpm (.. )

I have a pass these values to a interpn function such a way it should pass as set of values, which means i should pass like Position = "ITC" and direction = 0.34 , during the next position = "VTC" and direction = 0.56 and the last one. how do i do that  ?


Reply | Threaded
Open this post in threaded view
|

Re: Passing the values in a fixed format

nrjank
Administrator
On Wed, Jun 24, 2020 at 1:17 PM Ganesh Kini <[hidden email]> wrote:
I have 2 arrays

Position = {"ITC""VTC""KZT"};

Direction = [0.34 0.56 0.99]


I have a pass these values to a interpn function such a way it should pass as set of values, which means i should pass like Position = "ITC" and direction = 0.34 , during the next position = "VTC" and direction = 0.56 and the last one. how do i do that  ?


so it seems you want to pass all of the first ones, process them, then all of the second ones, process them, etc., up until the end of the list.  You can pass them by index.  Recommend reading the following on how to work with arrays and subsets by indexing:


specifically to your question:

>> Position = {"ITC","VTC","KZT"}

Position =
{
  [1,1] = ITC
  [1,2] = VTC
  [1,3] = KZT
}

>> Direction = [0.34 0.56 0.99]

Direction =

   0.34000   0.56000   0.99000

>> Position(2)

ans =
{
  [1,1] = VTC
}

>> class(Position(2))

ans = cell
>> Position{2}

ans = VTC
>> class(Position{2})

ans = char
>> Direction(2)

ans =  0.56000


working with a for loop (just printing them to the screen, you can do whatever you want with them):

>> for idx = 1:numel(Direction)
  printf("%s %f\n",Position{idx},Direction(idx));
endfor

ITC 0.340000
VTC 0.560000
KZT 0.990000




DrD
Reply | Threaded
Open this post in threaded view
|

Re: Passing the values in a fixed format

DrD
In reply to this post by GK19
Trouble Using Functions

I've written a short script to use functions, and it does not run for me (it says the first function encountered is not defined). Any help would be appreciated. Here is my script:

% TestFile1
p=[1;2;3]
q=[3;4;7]
ssq=s2(q);
[add,subt]=s1(p,q);

function [sum,diff]=s1(a,b)
  print "   Function s1 -- sum and difference"
  sum=a+b
  diff=a-b
endfunction
function sumsq=s2(a)
  print "   Function s2 -- sum of squares"
  sumsq=a'*a
endfunction

Virus-free. www.avast.com

On Wed, Jun 24, 2020 at 12:17 PM Ganesh Kini <[hidden email]> wrote:
I have 2 arrays

Position = {"ITC""VTC""KZT"};

Direction = [0.34 0.56 0.99]

abc = interpm (.. )

I have a pass these values to a interpn function such a way it should pass as set of values, which means i should pass like Position = "ITC" and direction = 0.34 , during the next position = "VTC" and direction = 0.56 and the last one. how do i do that  ?



Reply | Threaded
Open this post in threaded view
|

Re: Passing the values in a fixed format

nrjank
Administrator
please create a new email thread instead of replying to this one.  People might miss your question as the subject line does not match your inquiry.