필터 지우기
필터 지우기

Plotting P-v graph using function file

조회 수: 1 (최근 30일)
Roopali Hothi
Roopali Hothi 2018년 12월 15일
편집: TADA 2018년 12월 15일
Hi everyone.
I am new to Matlab.
I have been assigned to a project where I have to plot the pressure-specific volume graph of steam. I am to obtain my values of specific volume using a pre existing function file named SteamIC.m (what is to be entered into the main module is shown below)
v= SteamIC('vV_p', In1), where In1 is the input argument (in this case pressure)
I have defined my range of pressure values as linspace(0.0061248,220.64)
My issue is that the input argument (In1) must be a single value (scalar)
How am I to find out all of the specific volume values using the pressure range above? As I can only put in one pressure value at a time
Any help appreciated

채택된 답변

TADA
TADA 2018년 12월 15일
편집: TADA 2018년 12월 15일
v = zeros(1, length(In1));
for i = 1:length(In1)
v(i) = SteamIC('vV_p', In1(i));
end
or the shorter version using arrayfun:
v = arrayfun(@(a) SteamIC('vV_p', a), In1);
  댓글 수: 4
Roopali Hothi
Roopali Hothi 2018년 12월 15일
Ah I see.
My other question was whether there was a way of storing the value of v calculated in each loop, just before the loop is ended and restarts to calculate a new value of v.
In other words, you used an external function (that was outside the loop) to store the v value. Is there something I can put into the loop itself to store the value of v?
TADA
TADA 2018년 12월 15일
편집: TADA 2018년 12월 15일
If I Follow, then By function Mean the vector (or Array) v?
I That Case You Can Define Varriables of Any Type Inside Any Control Block (loop, If/Else, Switch, Try/Catch/Finally, etc.)
Bear In Mind That By Declaring Something inside A Loop, It Will Be Overwritten In the next Iteration Of The Loop .

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by