Why my plot is not showing?

3 visualizzazioni (ultimi 30 giorni)
Fabricio Macias
Fabricio Macias il 29 Ott 2020
Commentato: Ameer Hamza il 29 Ott 2020
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 Commento
Fabricio Macias
Fabricio Macias il 29 Ott 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

Accedi per commentare.

Risposta accettata

Ameer Hamza
Ameer Hamza il 29 Ott 2020
Modificato: Ameer Hamza il 29 Ott 2020
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 Commenti
Fabricio Macias
Fabricio Macias il 29 Ott 2020
I found the error, I wrote real instead of reel. Thank you again
Ameer Hamza
Ameer Hamza il 29 Ott 2020
Yes, reel was the type.
I am glad to be of help!

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by