how i can select an indice in vector and matrix

2 views (last 30 days)
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

Accepted Answer

Cedric
Cedric on 26 Apr 2013
Edited: Cedric on 26 Apr 2013
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 Comments
ilyas ilyas
ilyas ilyas on 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
Cedric
Cedric on 26 Apr 2013
You can interpolate as follows
[T_mesh, phi_mesh] = meshgrid(T, phi) ;
value = interp2(T_mesh, phi_mesh, Cs, tx, phix) ;

Sign in to comment.

More Answers (3)

ilyas ilyas
ilyas ilyas on 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

ilyas ilyas
ilyas ilyas on 26 Apr 2013
Edited: ilyas ilyas on 16 May 2013
for more explaine this pic will be do that
how i can select the indices plz
  3 Comments
ilyas ilyas
ilyas ilyas on 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 on 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.

Sign in to comment.


ilyas ilyas
ilyas ilyas on 27 Apr 2013
Edited: ilyas ilyas on 16 May 2013
thank you Mr. Cedric the prob was finished

Community Treasure Hunt

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

Start Hunting!