Why my plot is not showing?

3 ビュー (過去 30 日間)
Fabricio Macias
Fabricio Macias 2020 年 10 月 29 日
コメント済み: Ameer Hamza 2020 年 10 月 29 日
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 件のコメント
Fabricio Macias
Fabricio Macias 2020 年 10 月 29 日
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

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 29 日
編集済み: Ameer Hamza 2020 年 10 月 29 日
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 件のコメント
Fabricio Macias
Fabricio Macias 2020 年 10 月 29 日
I found the error, I wrote real instead of reel. Thank you again
Ameer Hamza
Ameer Hamza 2020 年 10 月 29 日
Yes, reel was the type.
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by