how to load .txt data into a function and use it as variables in matlab function

Hi All,
I would like to use my out source data (in .txt), into finding a graph. The data is b = a070_edit(:,1) are an variables that are varies along the frquecy range. The 'b' data will be used as an varible in a function to find an unknown 'a'. and then a graph will be plotted (f vs a).
Actually my equation is much more complicated. Thus below I use a simple equation, so that it will be easier to solve the problem.
function
load a070_edit.txt % list of data from outsource
b = a070_edit(:,1)
d = 1;
t = 5./b;
f = 50:1.5625:5600;
w = 2.*pi.*f;
a = (d./t).*w
plot (f,a)
end
Kindly, please help me to load and use an external data into matlab function.
Your help will be appreciated.
Thank you.
Regards,
Nur Arafah

 Réponse acceptée

madhan ravi
madhan ravi le 16 Mai 2019
Modifié(e) : madhan ravi le 16 Mai 2019
B % just call it
function B % not if the file is input from outside the function then parameterize you function by providing an input for it
load a070_edit.txt % list of data from outsource
b = a070_edit(:,1);
d = 1;
t = 5./b;
f = 50:1.5625:5600;
w = 2.*pi.*f;
a = (d./t).*w;
plot(f,a)
end

3 commentaires

Dear madhan ravi,
Thank for your help.
The code works but the graph is not as what I'm expecting.
Capture.GIF
As 'b' is a parameter depending on f (which means each 'b' is for each 'f'). Thus, I'm expecting the graph to be 1 line only connecting each calculated value of 'a'.
I'm not very sure the 'data' is from where. Please correct me if i'm wrong.
P/S: the total value of 'b' attached is only about 10. But there are total of 3552 b's (which match with f = 50:1.5625:5600.
Tq.
b has 10 values , f has 3553 values
Hi madhan,
The problem solved.
Thanks alot.
=)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by