How to store function output as a matrix?

5 views (last 30 days)
Hi! I need help storing the output of P as a matrix so it would look like:
T P
0 corresponding value from P eqn
10 corresponding value from P eqn
20 corresponding value from P eqn
etc.
I am not the best with matlab, but any help would be appreciated. When I run the code, it becomes split apart. Thanks!
out = [];
for T = [0:10:100]
Volume = [0.0735560; 0.0736893; 0.0738233; 0.0739572; 0.0740910; 0.0742250; 0.0743592; 0.0744936; 0.0746282; 0.0747631; 0.0748981];
V0 = Volume(1,1); % index
V100 = Volume(11,1); % index
Temp = [0;10;20;30;40;50;60;70;80;90;100];
T0 = Temp(1,1); % index
T100 = Temp(11,1); % index
P = V0 + (((T - T0)*(V100 - V0))/(T100 - T0)); % simple equation
out = [T P]
end

Accepted Answer

KSSV
KSSV on 4 Sep 2020
Edited: KSSV on 4 Sep 2020
out = zeros([],2);
count = 0 ;
for T = [0:10:100]
Volume = [0.0735560; 0.0736893; 0.0738233; 0.0739572; 0.0740910; 0.0742250; 0.0743592; 0.0744936; 0.0746282; 0.0747631; 0.0748981];
V0 = Volume(1,1); % index
V100 = Volume(11,1); % index
Temp = [0;10;20;30;40;50;60;70;80;90;100];
T0 = Temp(1,1); % index
T100 = Temp(11,1); % index
P = V0 + (((T - T0)*(V100 - V0))/(T100 - T0)); % simple equation
count = count+1 ;
out(count,:) = [T P]
end
OR
T = [0:10:100] ;
N = length(T) ;
out = zeros(1,N);
for i = 1:N
Volume = [0.0735560; 0.0736893; 0.0738233; 0.0739572; 0.0740910; 0.0742250; 0.0743592; 0.0744936; 0.0746282; 0.0747631; 0.0748981];
V0 = Volume(1,1); % index
V100 = Volume(11,1); % index
Temp = [0;10;20;30;40;50;60;70;80;90;100];
T0 = Temp(1,1); % index
T100 = Temp(11,1); % index
P = V0 + (((T(i) - T0)*(V100 - V0))/(T100 - T0)); % simple equation
count = count+1 ;
out(i) = P ;
end
[T' out']
  1 Comment
Wonderboy130
Wonderboy130 on 4 Sep 2020
Thank you! The latter code works perfectly. I've spent so long trying to figure it out.

Sign in to comment.

More Answers (1)

David Hill
David Hill on 4 Sep 2020
out = [];
for T = [0:10:100]
Volume = [0.0735560; 0.0736893; 0.0738233; 0.0739572; 0.0740910; 0.0742250; 0.0743592; 0.0744936; 0.0746282; 0.0747631; 0.0748981];
V0 = Volume(1,1); % index
V100 = Volume(11,1); % index
Temp = [0;10;20;30;40;50;60;70;80;90;100];
T0 = Temp(1,1); % index
T100 = Temp(11,1); % index
P = V0 + (((T - T0)*(V100 - V0))/(T100 - T0)); % simple equation
out = [out;T,P];
end

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!