how i can select an indice in vector and matrix

Hello guys i have a problem to select an indice in matlab for ex: i have this programme:
T=[0 10 20 30 40 50]; % température en°C
phi=[0 20 40 60 80 100]; % Humidité relative en %
Cs =
0.2685 0.3110 0.3501 0.3857 0.4192 0.4528
0.2691 0.3079 0.3449 0.3785 0.4093 0.4368
0.2690 0.3048 0.3394 0.3708 0.3991 0.4229
0.2688 0.3025 0.3345 0.3635 0.3893 0.4107
0.2692 0.3016 0.3313 0.3576 0.3806 0.3999
0.2709 0.3031 0.3309 0.3538 0.3738 0.3900
we can imagine this like that
0 10 20 30 40 50
0 0.2685 0.3110 0.3501 0.3857 0.4192 0.4528
20 0.2691 0.3079 0.3449 0.3785 0.4093 0.4368
40 0.2690 0.3048 0.3394 0.3708 0.3991 0.4229
60 0.2688 0.3025 0.3345 0.3635 0.3893 0.4107
80 0.2692 0.3016 0.3313 0.3576 0.3806 0.3999
100 0.2709 0.3031 0.3309 0.3538 0.3738 0.3900
so i want to when i input temperature and humidity the programme select the Cs's value
for ex: if i do that
tx=input('chose your température plz')
phix=input('chose your humidity plz')
and i chose tx=10 & phix=20 the result will be
Csx=0.3079
i hope i explained my problem and i'm waiting your answers

2 Kommentare

Cedric
Cedric am 26 Apr. 2013
"Guys" actually ;-D
ilyas ilyas
ilyas ilyas am 26 Apr. 2013
i'm so sorry for my bed english lang

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Cedric
Cedric am 26 Apr. 2013
Bearbeitet: Cedric am 26 Apr. 2013

1 Stimme

If you are sure that phix and tx will be entered so they match exactly elements of T and phi, you can do the following:
id_T = find(T == tx) ;
id_phi = find(phi == phix) ;
Csx = Cs(id_phi, id_T) ;
If you aren't sure and you want to take the closest t and phi, you can do
[~,id_T] = min(abs(diff_T-tx)) ;
[~,id_phi] = min(abs(phi-phix)) ;
Csx = Cs(id_phi, id_T) ;
You could also interpolate, but that's another story.

2 Kommentare

ilyas ilyas
ilyas ilyas am 26 Apr. 2013
yah i wanna to interpolat and i have the eqt to calcul the Csx but i have a prob to select the indices if i have an value doesn't exict in vectors for ex: if i have tx= 22 & phix= 15 this values doesn't exict but i know by interpolation i use (1,3);(1,4);(2,3);(2,4) so how i can do that
You can interpolate as follows
[T_mesh, phi_mesh] = meshgrid(T, phi) ;
value = interp2(T_mesh, phi_mesh, Cs, tx, phix) ;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

ilyas ilyas
ilyas ilyas am 26 Apr. 2013

0 Stimmen

yah i wanna to interpolat and i have the eqt to calcul the Csx but i have a prob to select the indices if i have an value doesn't exict in vectors for ex: if i have tx= 22 & phix= 15 this values doesn't exict but i know by interpolation i use (1,3);(1,4);(2,3);(2,4) so how i can do that
ilyas ilyas
ilyas ilyas am 26 Apr. 2013
Bearbeitet: ilyas ilyas am 16 Mai 2013

0 Stimmen

for more explaine this pic will be do that
how i can select the indices plz

3 Kommentare

Cedric
Cedric am 27 Apr. 2013
This is essentially what INTERP2 does in my comment above, so there is little interest in re-implementing it by yourself (unless it is for a homework and you have to implement it by yourself).
So try using INTERP2; look up for examples in the official documentation and/or online if you need more than my example.
ilyas ilyas
ilyas ilyas am 27 Apr. 2013
hello it's not for a homework it's for my project:) i try to use the interp2 but the result is not the same
Cedric
Cedric am 27 Apr. 2013
At what point did you make the test and what/how did you compute.
The issue if you really want to implement your formula by hand is that you will have to manage quite a few special cases, which means that you will have to implement more code that just the formula that you have above.

Melden Sie sich an, um zu kommentieren.

ilyas ilyas
ilyas ilyas am 27 Apr. 2013
Bearbeitet: ilyas ilyas am 16 Mai 2013

0 Stimmen

thank you Mr. Cedric the prob was finished

1 Kommentar

Cedric
Cedric am 28 Apr. 2013
Ok, great if you found a solution; bonne continuation !

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by