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

Cedric
Cedric 2013년 4월 26일
"Guys" actually ;-D
i'm so sorry for my bed english lang

댓글을 달려면 로그인하십시오.

 채택된 답변

Cedric
Cedric 2013년 4월 26일
편집: Cedric 2013년 4월 26일

1 개 추천

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

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) ;

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

ilyas ilyas
ilyas ilyas 2013년 4월 26일

0 개 추천

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 2013년 4월 26일
편집: ilyas ilyas 2013년 5월 16일

0 개 추천

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

댓글 수: 3

Cedric
Cedric 2013년 4월 27일
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.
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 2013년 4월 27일
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.

댓글을 달려면 로그인하십시오.

ilyas ilyas
ilyas ilyas 2013년 4월 27일
편집: ilyas ilyas 2013년 5월 16일

0 개 추천

thank you Mr. Cedric the prob was finished

댓글 수: 1

Cedric
Cedric 2013년 4월 28일
Ok, great if you found a solution; bonne continuation !

댓글을 달려면 로그인하십시오.

카테고리

질문:

2013년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by