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

6 visualizzazioni (ultimi 30 giorni)
HZ-RAW il 11 Gen 2022
Commentato: Ive J il 12 Gen 2022
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
y2=[10000000,1000000,100000,10000]; %Tryck,P
x2=[log(0.001452),log(0.06294),log(0.7434),log(7.457)]; %volymitet,v
y3=[10000000,1000000,100000,10000]; %Tryck,P
x3=[log(0.01803),log(0.1893),log(1.813),log(18.11)]; %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)
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:
% 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);
[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?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Ive J il 11 Gen 2022
Modificato: Ive J il 11 Gen 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);
plot(h, Pkurva, vfkurva)
hold off
% 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);
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end
##### 2 CommentiMostra NessunoNascondi Nessuno
HZ-RAW il 12 Gen 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
y2=[10000000,1000000,100000,10000]; %Tryck,P
x2=[log(0.001452),log(0.06294),log(0.7434),log(7.457)]; %volymitet,v
y3=[10000000,1000000,100000,10000]; %Tryck,P
x3=[log(0.01803),log(0.1893),log(1.813),log(18.11)]; %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,'-*');
plot(h,Pkurva,vfkurva,vgkurva)
ylabel('P')
xlabel('v')
hold on
grid on
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 il 12 Gen 2022
Your function doesn't make any sense:
% where x and y are being used?
Tm=[0.01 1:373 373.946];
Pkurva=pmatt_ASME(Tm);
[vfkurva,vgkurva]=vmatt_ASME(Tm);
end

Accedi per commentare.

### Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by