How to store function output as a matrix?
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KSSV
2020-9-4
编辑:KSSV
2020-9-4
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 个)
David Hill
2020-9-4
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!