필터 지우기
필터 지우기

displaying values in command window

조회 수: 9 (최근 30일)
harley
harley 2013년 8월 6일
hi, trying to display some values but am not sure how to go about it, this is a pH array, Vb is volume of base added. What i am trying to do is display the midpoint to equivalence which is the half of Vb_ev and then display the corresponding pH value at midpoint, which i know is approx 4.756. see on from line 6 from the bottom.
format short
Kw = 1e-14;
Ka = 1.755388e-5;
pKa = 4.756;
%
Ca = 0.5;
Cb = 0.1;
Va = 100;
Vb = 0.05:0.05:2000;
Ma = (Ca * Va) / 1000;
Mb = (Cb .* Vb) ./ 1000;
for i = 1:length(Mb)
M_excess = Ma - Mb(i);
if abs(M_excess)<eps
Hplus = Ka * ((Ma_final * 0.999999) ./ Mb_final);
Vb_ev = Vb(i);
pH_ev = pH(end);
elseif M_excess > 0
Ma_final = (M_excess * 1000) ./ (Va + Vb(i));
Mb_final = (Mb(i) * 1000) ./ (Va + Vb(i));
Hplus = Ka * (Ma_final ./ Mb_final);
elseif M_excess < 0
OH = (M_excess * 1000 * (-1)) ./ (Va + Vb(i));
Hplus = Kw ./ OH;
end
pH(i) = -log10(Hplus);
end
%
Vb_Mid_Pt1 = (Vb_ev)*0.5;
pH_Mid_Pt1 = i want to display pH at Vb_Mid_Pt1;
disp('The Volume is, mL:')
disp(Vb_Mid_Pt1)
disp('The pH is:')
disp(pH_Mid_Pt1)
  댓글 수: 2
David Sanchez
David Sanchez 2013년 8월 6일
use the {}Code button to properly present your code, please.
Jan
Jan 2013년 8월 6일
"No luck" is a not a good description of the problem and of what you actually want. The less the readers have to guess, the more likely is a matching answer.

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

채택된 답변

kedija
kedija 2013년 8월 6일
the reason you are getting such error is the index Vb_Mid_Pt1 is not integer. if u cast that it works fine. here you go
format short
Kw = 1e-14;
Ka = 1.755388e-5;
pKa = 4.756;
%
Ca = 0.5;
Cb = 0.1;
Va = 100;
Vb = 0.05:0.05:2000;
Ma = (Ca * Va) / 1000;
Mb = (Cb .* Vb) ./ 1000;
for i = 1:length(Mb)
M_excess = Ma - Mb(i);
if abs(M_excess)<eps
Hplus = Ka * ((Ma_final * 0.999999) ./ Mb_final);
Vb_ev = Vb(i);
pH_ev = pH(end);
elseif M_excess > 0
Ma_final = (M_excess * 1000) ./ (Va + Vb(i));
Mb_final = (Mb(i) * 1000) ./ (Va + Vb(i));
Hplus = Ka * (Ma_final ./ Mb_final);
elseif M_excess < 0
OH = (M_excess * 1000 * (-1)) ./ (Va + Vb(i));
Hplus = Kw ./ OH;
end
pH(i) = -log10(Hplus);
end
%
Vb_Mid_Pt1 = uint16(Vb_ev)*0.5;
pH_Mid_Pt1 = pH(Vb_Mid_Pt1);%i want to display pH at Vb_Mid_Pt1;
disp('The Volume is, mL:')
disp(Vb_Mid_Pt1)
disp('The pH is:')
disp(pH_Mid_Pt1)
  댓글 수: 4
harley
harley 2013년 8월 6일
thanks kedija, im trying to get it to return the corresponding pH value when;
Vb = Vb_env*0.5
both these values are in column 5000. I get a pH value of 3.1646 which corresponds to column 250, which is the value obtained from;
Vb_Mid_Pt1 = uint16(Vb_ev)*0.5;
The pH should be around 4.756. I think my problem lies with the above expression.
thanks in advance.
kedija
kedija 2013년 8월 6일
편집: kedija 2013년 8월 6일
I don't really know what your code does but Vb_ev is 500 and it is giving you the 250th value. if you want to display the 5000 value change ur code somehow to correct ur index. pH(5000) is 4.7556 .... I think you are messing something in the index.

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

추가 답변 (1개)

David Sanchez
David Sanchez 2013년 8월 6일
I hope this is what you want to do:
my_var = 3;
fprintf('The value of my variable is : %g \n' ,my_var);
OUTPUT:
The value of my variable is : 3

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by