Hello, I'm new to matlab. For a homework I need to plot a spline from two vectors.
file = fopen('data_xi.txt');
reel = fscanf(file, '%f', [14]);
fclose(file)
file = fopen('data_yi.txt');
imag = fscanf(file, '%f', [14]);
fclose(file)
xx = 0:.05:8;
yy = spline(reel,imag,xx);
figure(1)
plot(real,imag,'o',xx,yy);
xlabel('Voltage(mV)') ;
ylabel('Current(A)') ;
I'm not sure I understand how spline works, I just copied an example and tried to apply it to my case. When I run the code, the plot window opens but nothing shows up.
Thanks for any help

1 Kommentar

Fabricio Macias
Fabricio Macias am 29 Okt. 2020
The data_xi has this values :
0.00000000
7.00000003E-02
0.730000019
1.42999995
3.41000009
6.01000023
7.32000017
7.59000015
7.67999983
7.76999998
7.80999994
7.88000011
7.90999985
7.92000008
And data_yi:
745.000000
744.000000
736.000000
729.000000
696.000000
615.000000
460.000000
331.000000
258.000000
187.000000
151.000000
98.5999985
67.5999985
46.4000015

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 29 Okt. 2020
Bearbeitet: Ameer Hamza am 29 Okt. 2020

0 Stimmen

The following code works correctly on my system. This was a little type in your code
file = fopen('data_xi.txt');
reel = fscanf(file, '%f', [14]);
fclose(file)
file = fopen('data_yi.txt');
imag = fscanf(file, '%f', [14]);
fclose(file)
xx = 0:.05:8;
yy = spline(reel,imag,xx);
figure(1)
plot(reel,imag,'o',xx,yy);
xlabel('Voltage(mV)') ;
ylabel('Current(A)') ;
The .txt files are also attached.

3 Kommentare

Fabricio Macias
Fabricio Macias am 29 Okt. 2020
Thank you so much! I can't tell the difference, but at least it works!
Fabricio Macias
Fabricio Macias am 29 Okt. 2020
I found the error, I wrote real instead of reel. Thank you again
Ameer Hamza
Ameer Hamza am 29 Okt. 2020
Yes, reel was the type.
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by