How can I call a function from a different script into a plot with other plot-values?

19 views (last 30 days)
I have the following values in my first script that can be plotted into a graph:
Script1:(The green text is in Swedish)
%%
close all
clear
clc
%P mot v
%Underkyld vätska: Tryck,P mot volymitet,v
y1=[10000000,1000000,100000,10000]; %Tryck,P
x1=[log(0.0009973),log(0.001002),log(0.001002),log(0.001002)]; %volymitet,v
%Mättad vätska: Tryck,P mot volymitet,v
y2=[10000000,1000000,100000,10000]; %Tryck,P
x2=[log(0.001452),log(0.06294),log(0.7434),log(7.457)]; %volymitet,v
%Mättad ånga: Tryck,P mot volymitet,v
y3=[10000000,1000000,100000,10000]; %Tryck,P
x3=[log(0.01803),log(0.1893),log(1.813),log(18.11)]; %volymitet,v
%Överhettad ånga: Tryck,P mot volymitet,v
y4=[10000000,1000000,100000,10000]; %Tryck,P
x4=[log(0.03278),log(0.3312),log(3.316),log(33.16)]; %volymitet,v
figure(1)
[Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(x);
plot(x1,y1,'-*',x2,y2,'-*',x3,y3,'-*',x4,y4,'-*',f(x))
ylabel('P')
xlabel('v')
hold on
grid on
But I also want to plot this following function into the same graph as in script1:
Script2:
function [Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O()
% Funktion som tar fram p- och v-data för mättnadskurvorna för vatten
% Temperaturvektorn (mättnadsdata är funktioner av temperaturen) för kurvorna
% (kurvorna går från 0.01°C till 373.946°C)
Tm=[0.01 1:373 373.946];
% Tryckvektor för kurvorna (samma för båda)
Pkurva=pmatt_ASME(Tm);
% Volymiteterna, både mättad vätska och mättad ånga
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end
This function plots a certain curve that helps me to analyze my data more accurately in my project. (P stands for pressure and v for volume) How do I do this? What input code do I need to type in Script1?

Answers (1)

Ive J
Ive J on 11 Jan 2022
Edited: Ive J on 11 Jan 2022
Something's wrong with your second function, seems there is no input argument(s). vmatt_ASME doesn't accept any argument rather Tm. Maybe Tm is supposed to be the input argument of PM_mattnadPv_H2O func? Because the second function uses Tm to calculate P and V (as far as I understood). In that case you can return P and V and plot them on the same axis as in script 1.
hold on
h = plot(x, y);
[Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(tm);
plot(h, Pkurva, vfkurva)
hold off
And your function would be
function [Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(Tm)
% Funktion som tar fram p- och v-data för mättnadskurvan för vatten
% Temperaturvektorn (mättnadsdata är funktioner av temperaturen) för kurvorna
% (kurvorna går från 0.01°C till 373.946°C)
% Tm=[0.01 1:373 373.946];
% Tryckvektor för kurvorna (samma för båda)
Pkurva=pmatt_ASME(Tm);
% Volymiteterna, både mättad vätska och mättad ånga
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end
  2 Comments
HZ-RAW
HZ-RAW on 12 Jan 2022
I did what you instructed but without success. I later edited the code like this:
%%
close all
clear
clc
%P mot v
%Underkyld vätska: Tryck,P mot volymitet,v
y1=[10000000,1000000,100000,10000]; %Tryck,P
x1=[log(0.0009973),log(0.001002),log(0.001002),log(0.001002)]; %volymitet,v
%Mättad vätska: Tryck,P mot volymitet,v
y2=[10000000,1000000,100000,10000]; %Tryck,P
x2=[log(0.001452),log(0.06294),log(0.7434),log(7.457)]; %volymitet,v
%Mättad ånga: Tryck,P mot volymitet,v
y3=[10000000,1000000,100000,10000]; %Tryck,P
x3=[log(0.01803),log(0.1893),log(1.813),log(18.11)]; %volymitet,v
%Överhettad ånga: Tryck,P mot volymitet,v
y4=[10000000,1000000,100000,10000]; %Tryck,P
x4=[log(0.03278),log(0.3312),log(3.316),log(33.16)]; %volymitet,v
figure(1)
h=plot(x1,y1,'-*',x2,y2,'-*',x3,y3,'-*',x4,y4,'-*');
[Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(x,y);
plot(h,Pkurva,vfkurva,vgkurva)
ylabel('P')
xlabel('v')
hold on
grid on
function [Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(x,y)
Tm=[0.01 1:373 373.946];
Pkurva=pmatt_ASME(Tm);
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end
I don't know if I use the correct input arguments "x,y" but I basically need to call the fuction PM_mattnadPv_H2O into the graph, but still unsuccessful in this current state.
Ive J
Ive J on 12 Jan 2022
Your function doesn't make any sense:
function [Pkurva,vfkurva,vgkurva]=PM_mattnadPv_H2O(x,y)
% where x and y are being used?
Tm=[0.01 1:373 373.946];
Pkurva=pmatt_ASME(Tm);
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end
PM_mattnadPv_H2O doesn't use x and y whatsoever! Modify your function arguments.

Sign in to comment.

Categories

Find more on Graphics Object Programming 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!